0

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

2 回答 2

0

Your problem is with the call to header; Remove the space between Location and :

header("Location: $insertGoTo");

OR in your code style:

header(sprintf("Location: %s", $insertGoTo));
于 2013-09-06T16:51:26.223 回答
0

As per my original comment: (link)

Because of the space between Location and the semi-colon :

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

Try:

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

that alone will fail. Try it now with that.

Consult the PHP manual on the header() function. http://php.net/manual/en/function.header.php

于 2013-09-06T16:54:20.127 回答