我有一个主表单,它有一个提交按钮,当按下它时,它会使用插入查询插入员工数据,但是当我按下表单中的提交按钮时,它会打开一个空白页面,因为结果表单中没有可见的内容。我怎样才能得到它,以便当我按下提交按钮时它只是输入数据但保持在同一个表单上并且不会打开空白页面。这甚至可能吗?我是否必须简单地将 index.php 的样式复制到 process.php 文件中?请帮助我是新手并想学习。
这是我的代码(index.php)
<html>
<head>
</head>
<body>
<form action="process.php" method="post" style="position:relative; top:200px;left:150px">
First Name: <input type="text" style="position:relative;left:14px"name="firstName"><br>
Last Name: <input type="text" style="position:relative;left:15px"name="lastName"><br>
<input type="submit"style="position:relative;left:88px"name="submitButton" ><br>
</form>
</body>
</html>
这是执行查询的结果 php 文件 (process.php)
<html>
<body>
<?php
$myServer = "MyComputerName\SQLEXPRESS";
$myUser = "Username";
$myPass = "password";
$myDB = "Northwind";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
$query = "Insert into Employees values ('".$_POST["firstName"]."','".$_POST["lastName"]."')";
mssql_query($query);
mssql_close();
?>
</body>
</html>