我在努力使事情變得簡單。當我輸入一個現有的電子郵件和錯誤的密碼都顯示錯誤。當我輸入錯誤的電子郵件地址和正確的密碼格式時,顯示電子郵件的錯誤消息,但是當我輸入錯誤的密碼和正確的電子郵件時,兩個錯誤消息都會顯示出來,而且應該只輸入錯誤的密碼。我只是一個初學者,我想知道這是如何工作的,但我在這裏找不到解決方案。我應該爲陣列使用不同的名稱嗎? 這裏是我的代碼:Php mysql錯誤信息
<?php
session_start();
$errmsg_arr = array();
$errflag = false;
//$errmsg_arr2 = array();
//$errflag2 = false;
include('config.php');
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$pword=$_POST['pword'];
$number=$_POST['number'];
$house=$_POST['house'];
$street=$_POST['street'];
$city=$_POST['city'];
$min_length = 6;
// you can set minimum length of the query if you want
$result = mysql_query("select 1 from athan_members where email='"
. mysql_real_escape_string($email) . "'");
$userExists = (mysql_fetch_array($result) !== FALSE);
mysql_free_result($result);
if ($userExists = true){
$errmsg_arr[] = 'email address is already used';
$errflag = true;
}
if(strlen($pword)< $min_length){
$errmsg_arr[] = 'password must contain not less than 6 characters';
$errflag = true;
}
else{
mysql_query("INSERT INTO athan_members (firstname, lastname, email, number, house1, street1, city, password) VALUES ('$firstname', '$lastname', '$email', '$number', '$house', '$street', '$city', '$pword')");
header("location: loginuser.php");
}
/*if(strlen($pword) >= $min_length){
//this one will not feed in the database if there's a duplicate but still a problem ohmaygawd:3
//mysql_query("INSERT INTO athan_members (firstname, lastname, email, number, house1, street1, city, password) VALUES ('$firstname', '$lastname', '$email', '$number', '$house', '$street', '$city', '$pword') ON DUPLICATE KEY UPDATE")
mysql_query("INSERT INTO athan_members (firstname, lastname, email, number, house1, street1, city, password) VALUES ('$firstname', '$lastname', '$email', '$number', '$house', '$street', '$city', '$pword')");
header("location: loginuser.php");
}
else
{
$errmsg_arr[] = 'password must contain not less than 6 characters';
$errflag = true;
}*/
if ($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: new.php");
exit();
}
mysql_close($con);
?>
你需要在調用頭文件後調用'exit()',並且在執行SQL語句之前需要清理變量。 –