我无法理解这个错误。
PHP错误:尝试获取非对象的属性
此行显示错误:if ($data->num_rows > 0)
我是php的新手,所以我很难解决这个问题。
源代码:
<?php
if (isset($_GET["token"]) && isset($_GET["email"])) {
$connection = new mysqli("localhost", "root", "", "hackathon");
$email = $connection->real_escape_string($_GET["email"]);
$token = $connection->real_escape_string($_GET["token"]);
$data = $connection->query("SELECT id
FROM registration
WHERE email='$email'
AND token='$token'
AND token <> ''
AND expire> NOW()");
if ($data->num_rows > 0) { // Error in this line
$str = "0123456789qwertzuioplkjhgfdsayxcvbnm";
$str = str_shuffle($str);
$str = substr($str, 0, 15);
$password = sha1($str);
$connection->query("UPDATE registration SET password = '$password', token = '' WHERE email='$email'");
echo "Your new password is: $str";
} else {
echo "Please check your link!";
}
} else {
header("Location: index.php");
exit();
}
?>