插入MySQL表PHP重定向

插入MySQL表PHP重定向,php,sql-insert,Php,Sql Insert,我有一个简单的表单将数据插入MySQL表。我希望用户在点击提交后返回index.php我有两个文件index.php和insert.php <?php $con = mysql_connect("xxxxxx", "xxxxxx", ""); mysql_select_db("foster", $con); if(isset($_POST['submit'])) { $ID=$_POST['ID']; $firstName

我有一个简单的表单将数据插入MySQL表。我希望用户在点击提交后返回index.php我有两个文件index.php和insert.php

    <?php
    $con = mysql_connect("xxxxxx", "xxxxxx", "");
    mysql_select_db("foster", $con);

  if(isset($_POST['submit']))
   {
        $ID=$_POST['ID'];
        $firstName=$_POST['firstName'];
        $lastName=$_POST['lastName'];

            $query = mysql_query("insert into customers(ID, firstName, lastName) values ('$ID', '$firstName', '$lastName')");



     }

   ?>

    <form action="index.php" method="post">
        ID: <input type="text" name="ID"/>
        <br/>
        First Name: <input type="text" name="firstName"/>
        <br/>
        Last Name: <input type="text" name="lastName"/>
        <br/>
        <input name="submit" type="submit" value="INSERT CUSTOMER"/>
    </form>
insert.php

    <?php
    $con = mysql_connect("xxxxxx", "xxxxxx", "");
    mysql_select_db("foster", $con);

  if(isset($_POST['submit']))
   {
        $ID=$_POST['ID'];
        $firstName=$_POST['firstName'];
        $lastName=$_POST['lastName'];

            $query = mysql_query("insert into customers(ID, firstName, lastName) values ('$ID', '$firstName', '$lastName')");



     }

   ?>

    <form action="index.php" method="post">
        ID: <input type="text" name="ID"/>
        <br/>
        First Name: <input type="text" name="firstName"/>
        <br/>
        Last Name: <input type="text" name="lastName"/>
        <br/>
        <input name="submit" type="submit" value="INSERT CUSTOMER"/>
    </form>
我的问题是,每次我将action更改为index.php时,表不会更改,但如果use action=正在工作

如果要在insert.php中插入数据,请更改为

插入后,将页面跳转到index.php


只需在插入查询后添加以下内容:

header("Location: index.php");
exit;

插入后它将重定向到index.php

当然,它在index.php上不起作用,您的插入代码在insert.phpindex.php上=还有别的办法吗?老天,冷静点伙计们,我没那么做