Php 表单提交后重定向

Php 表单提交后重定向,php,forms,redirect,Php,Forms,Redirect,我有以下正确发布的代码,但我想重定向到site index.php页面,无法理解。我到处都找遍了,几乎什么都试过了,但没有成功。谢谢你的帮助 $editFormAction = $_SERVER['PHP_SELF']; $query_dupUserCheck = "SELECT tblUser.userKey FROM tblUser WHERE tblUser.username = '".$_POST['username']."'"; $sqlsearch = mysql_

我有以下正确发布的代码,但我想重定向到site index.php页面,无法理解。我到处都找遍了,几乎什么都试过了,但没有成功。谢谢你的帮助

$editFormAction = $_SERVER['PHP_SELF'];

    $query_dupUserCheck = "SELECT tblUser.userKey FROM tblUser WHERE tblUser.username = '".$_POST['username']."'";
    $sqlsearch = mysql_query($query_dupUserCheck);
    $resultcount = mysql_numrows($sqlsearch);

    $query_dupUserCheck2 = "SELECT tblUser.userKey FROM tblUser WHERE tblUser.email = '".$_POST['user_email']."'";
    $sqlsearch2 = mysql_query($query_dupUserCheck2);
    $resultcount2 = mysql_numrows($sqlsearch2);

    if ($resultcount > 0 & $resultcount2 > 0) { 
        print("That Username and Email Already Exists");
    } else {
        if ($resultcount > 0) { 
            print("That Username Already Exists");  
        } else {
            if ($resultcount2 > 0) {    
            print("That Email Already Exists");
            } else {

if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "createAccount")) {
  $insertSQL = sprintf("INSERT INTO tblUser (username, password, userTypeKey, email) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['user_password2'], "text"),
                       GetSQLValueString($_POST['userType'], "int"),
                       GetSQLValueString($_POST['user_email'], "text"));

  mysql_select_db($database_ignite, $ignite);
  $Result1 = mysql_query($insertSQL, $ignite) or die(mysql_error());

  $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
header(sprintf("Location : %s", $insertGoTo));
}
}}}
表单使用

<?php echo $editFormAction;?>

您的问题在于对header的调用;删除位置和之间的空间:

header("Location: $insertGoTo");
或者以您的代码样式:

header(sprintf("Location: %s", $insertGoTo));

因为
位置
和分号之间的空格

header(sprintf("Location : %s", $insertGoTo));
// ---------------------^
尝试:

单凭这一点是行不通的。现在试试这个


关于
header()
函数,请参阅PHP手册

因为
标题中有空格(sprintf(“位置:%s”,“insertGoTo”)
位置
之间:
尝试
标题(sprintf(“位置:%s”,$insertGoTo))仅此一项将失败。现在就试试吧。你可以用javascript来做this@user2752153还有其他问题,我无法使用您的代码进行测试,但是
位置
和分号之间的空间肯定是一个因素。我将看看我还可以做些什么来测试您的一些代码。@user2752153它可能与
$insertGoTo=“index.php”有关?我试着删除它,只是放上标题(“Location:index.php”);但仍然没有luck@user2752153由于这个
$editFormAction=$\u服务器['PHP\u SELF'],它保持在同一个页面上您需要将您的操作设置到另一个页面。@user2752153此
标题(“Location:index.php”)
不起作用,您需要在
位置
之间留出一个空格:
如下
标题(“Location:index.php”)非常重要。
header(sprintf("Location: %s", $insertGoTo));