如何在不打开php文件并显示空白页面的情况下执行insert查询?

如何在不打开php文件并显示空白页面的情况下执行insert查询?,php,html,Php,Html,我有一个主表单,它有一个提交按钮,按下该按钮时,它会使用插入查询插入员工数据,但当我在表单中按下提交按钮时,它会打开一个空白页,因为生成的表单中没有可见内容。我怎样才能得到它,当我按下提交按钮时,它只输入数据,但保持在同一个表单上,不会打开空白页。这可能吗?我是否需要简单地将index.php的样式复制到process.php文件中?请帮助我,我是新来的,想学习 这是我的代码(index.php) 名字: 姓氏: 下面是执行查询的结果php文件(process.php) 是的,有可能 1

我有一个主表单,它有一个提交按钮,按下该按钮时,它会使用插入查询插入员工数据,但当我在表单中按下提交按钮时,它会打开一个空白页,因为生成的表单中没有可见内容。我怎样才能得到它,当我按下提交按钮时,它只输入数据,但保持在同一个表单上,不会打开空白页。这可能吗?我是否需要简单地将index.php的样式复制到process.php文件中?请帮助我,我是新来的,想学习

这是我的代码(index.php)


名字:
姓氏:

下面是执行查询的结果php文件(process.php)


是的,有可能

1。AJAX

正如tymeJV在他的评论中已经提到的:您可以使用AJAX来实现这一点

2。Change process.php

第二个选项是更改process.php文件


是的,这是可能的,看看AJAX将失败。使用
标题(“location:index.php”)-冒号后面的空格很重要。哎呀,你说得对极了。我太快了。。。好球!这太奇怪了,在过去的两天里,我已经看到这个错误至少15次了,哈哈!哦,好吧,只要能及时发现错误,干杯;-)感谢“header”(“location: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>
<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>
<?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();

  // Redirect
  header("location: index.php");
?>