MySQL不会从表中获取数据;为什么我的代码没有工作?
我试图检查密码是否正确但是由于某种原因它不会得到密码。我还应该注意,这段代码适用于Windows VPS,但现在我使用的是Ubuntu 14,它无法正常工作。我尝试过chmod 777,但这也没有帮助。关于我能做什么的任何想法?
if(isset($_COOKIE['user'])){
$username = mysql_real_escape_string($_COOKIE['user']);
mysql_connect($dbhost, $dbuser, $dbpass)or error("Could not connect: ".mysql_error());
mysql_select_db($dbname) or error(mysql_error());
$result = mysql_query("SELECT `id`, `username`, `password`, `ranks`, `active` FROM $table WHERE username='$username'") or die (mysql_error());
list($id,$username,$password,$rank,$active) = mysql_fetch_row($result);
if($_COOKIE['pass'] == $password) {
$display = "Hello, $username!";
} else {
$display = "Invalid Password, attempted post data fail?";
}
} else {
$display = "You are not logged in!";
}
答案 0 :(得分:0)
尝试:
$result = mysql_query("SELECT `id`, `username`, `password`, `ranks`, `active` FROM $table WHERE username='{$username}'") or die (mysql_error());
如果它不起作用,请告诉我如何在用户表中插入内容。您没有在PASSWORD()
上使用password
功能吗?
如果你这样做,试试这个:
$pass = $_COOKIE['pass'];
$result = mysql_query("SELECT `id`, `username`, `password`, `ranks`, `active` FROM $table WHERE username='{$username}' and password=PASSWORD('{$pass}')") or die (mysql_error());
if($result) {
list($id,$username,$password,$rank,$active) = mysql_fetch_row($result);
$display = "Hello, $username!";
} else {
$display = "You are not logged in!";
}