-1
好吧,我正在学习MySQLi,我很难让登录脚本表现得很好。它给我一个对非成员函数query()的非对象错误的调用。从我所读到的,这可能是因为我没有MySQLi的范围。我看不出错误在哪里,如果有人能指出并向我解释这个问题,我就会喜欢它。调用一个非对象的成员函数query()MySQLi
<?php session_start(); // Start PHP
// Get info sent to server from login form.
$my_username = $_POST['username'];
$my_password = $_POST['password'];
// MD5 Encrypt the password.
$my_password_md5 = md5($my_password);
// Define MySQL Information.
$db = new MySQLi('localhost', 'DBUSERNAME', 'DBPASS!', 'DB');
if ($db->connect_error) {
$error = $db->connect_error;
}
// Check table for username provided.
$sql="SELECT * FROM TABLE WHERE username='$my_username' and password='$my_password_md5'".
//this is where the error occurs
$result=$db->conn->query($sql) or die("Error in the consult.." . mysqli_error($db));
$rows=mysqli_fetch_assoc($result);
// Count how many rows match that information.
$count=mysqli_num_rows($result);
// Check if there are any matches.
if($count==1){
// If so, register $my_username, $my_password and redirect to the index page.
ini_set("session.gc_maxlifetime", "18000");
session_cache_expire(18000);
$cache_expire = session_cache_expire();
$_SESSION['username'] = $my_username;
$_SESSION['id'] = $rows['id'];
header("location:WEBSITE");
}
// If not, redirect back to the index page and provide an error.
else {
header("location:WEBSITE");
}
// End PHP
?>
你能突出显示错误发生的位置吗? – 2015-02-07 17:39:18
什么是'mysqli :: conn'应该是? (请参阅[文档](http://php.net/manual/en/book.mysqli.php)) – Sumurai8 2015-02-07 17:39:40
错误发生在第14行,其中$ result开始 – 2015-02-07 17:41:51