我不知道爲什麼我的代碼無法重定向。我做了什麼錯誤... 它顯示的警告是 (((警告:無法修改標題信息 - 頭已經發出)))...請有人告訴我需要改變,以成功地重定向...我的代碼::header()無法重定向
<?php
include_once $_SERVER['DOCUMENT_ROOT'].'/include/db.inc.php' ;
$email = $_POST['email'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
if($password1 != $password2)
{
header('Location: http://localhost/home/');
echo "<script language=javascript> alert(\"RE-ENTERED PASSWORD DOESN'T MATCH WITH THE ORIGINAL ONE\");</script>";
exit();
}
if($firstname == "" or $firstname == "First Name")
{
header('Location: http://localhost/home/');
echo "<script language=javascript> alert(\"INVALID FIRST NAME\");</script>";
exit();
}
if($lastname == "" or $lastname == "Last Name")
{
header('Location: http://localhost/home/');
echo "<script language=javascript> alert(\"INVALID LAST NAME\");</script>";
exit();
}
//INSERTION INTO THE DATABASE STARTS FROM HERE.........
$email = mysqli_real_escape_string($link,$_POST['email']);
$password1= mysqli_real_escape_string($link,$_POST['password1']);
$firstname= mysqli_real_escape_string($link,$_POST['firstname']);
$lastname= mysqli_real_escape_string($link,$_POST['lastname']);
$password=md5($password1);
$sql = "INSERT INTO users SET
email = '$email',
password = '$password',
firstname = '$firstname',
lastname = '$lastname'";
if (!mysqli_query($link, $sql))
{
header('Location: http://localhost/home/');
echo "<script language=javascript> alert(\"THIS E-MAIL ID HAS ALREADY USED BEFORE !!!\");</script>";
exit();
}
else
{
header('Location: http://localhost/home/');
echo "<script language=javascript> alert(\"REGISTRATION SUCCESSFULLY COMPLETED !!! \");</script>";
exit();
}
?>
確保include/db.inc.php中沒有空格。一個'<?php [...]?>'('?>'後面的空格/換行符)會產生這個錯誤。 – tobspr 2013-02-20 12:19:13
重定向到新的URL **或**從當前URL輸出HTML。 *選一個*。 – Quentin 2013-02-20 12:20:17
@ TobSpr..no db.inc.php中沒有空格..必須有其他問題..請幫助 – 2013-02-20 12:26:10