我无法弄清楚为什么我在process.php页面上出现此错误:
Connected successfully
Could not run query: Table 'members_db.members where 'email' = '123456789'' doesn't exist
Invalid query: Duplicate entry '123456789' for key 'email'
没有多大意义,因为它似乎在错误信息中自相矛盾。
这是我的process.php:
<?php
session_start();
$con = mysql_connect('localhost', 'root', '');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
// make members the current db
$db_selected = mysql_select_db('members_db', $con);
if (!$db_selected) {
die ('Can\'t use members database : ' . mysql_error());
}
$hash_password = md5($_POST['password']);
$email = $_POST['email'];
$result = mysql_query("SELECT email,password FROM `members WHERE 'email' = '$email'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
$query = "INSERT INTO members (email, password)
VALUES('".$_POST['email']."','".$hash_password."')";
// Perform Query
$result2 = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result2) {
$message = 'Invalid query: ' . mysql_error() . "\n";
//$message .= 'Whole query: ' . $query;
die($message);
}
$_SESSION['email']=$_POST['email'];
$_SESSION['password']=$hash_password;
$_SESSION['loggedin']="YES";
$url = "Location: /welcome.php";
header($url);
}
$_SESSION['email']=$_POST['email'];
$_SESSION['password']=$hash_password;
$url = "Location: /checklogin.php";
header($url);
?>
这可能是一个愚蠢的错误,因为我正在学习这个项目。谢谢你的帮助!
答案 0 :(得分:5)
"SELECT email,password FROM `members WHERE 'email' = '$email'"
"SELECT email,password FROM `members` WHERE 'email' = '$email'"
你错过了反击=&gt; `
答案 1 :(得分:0)
更改
"SELECT email,password FROM `members WHERE 'email' = '$email'"
到
"SELECT email,password FROM `members` WHERE 'email' = '$email'"
答案 2 :(得分:0)
对于第一个错误:
更改第一个查询
$result = mysql_query("SELECT email,password FROM `members WHERE 'email' = '$email'");
到
$result = mysql_query("SELECT email,password FROM `members` WHERE email = '$email'");
第二个错误:
“重复条目”是因为您已经有一封包含相同数据的电子邮件,并且您的“电子邮件”列是唯一的,只需删除电子邮箱= 123456789的成员行。