表单提交php后重定向

时间:2013-09-06 16:45:59

标签: php forms redirect

我有以下代码正确发布,但我想重定向到站点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;?>

2 个答案:

答案 0 :(得分:0)

你的问题是对标题的调用;删除位置和:

之间的空格
header("Location: $insertGoTo");

OR代码样式:

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

答案 1 :(得分:0)

As per my original comment: (link)

由于Location和分号:

之间的空格
header(sprintf("Location : %s", $insertGoTo));
// ---------------------^

尝试:

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

仅此一项将失败。现在就试试吧。

参考header()函数的PHP手册。的 http://php.net/manual/en/function.header.php