我已将激活脚本从mysql转换为mysqli,但是一旦在电子邮件中单击链接,我的激活脚本就不会更新数据库。这是我的旧代码
function activate($email, $email_code) {
global $myConnection;
$email = mysqli_real_escape_string($email);
$email_code = mysqli_real_escape_string($email_code);
if (mysqli_result(mysqli_query($myConnection, "SELECT COUNT(`mem_id`) FROM `members` WHERE `mem_email` = '$email' AND `email_code` = '$email_code' AND `mem_emailactivated` = 0"), 0) == 1) {
mysqli_query($myConnection, "UPDATE `members` SET mem_emailactivated = 1 WHERE `mem_email` = '$email'");
return true;
} else {
return false;
}
}
这是我的新代码
function activate($email, $email_code) {
$myNewConnection = myConnection();
$email = mysqli_real_escape_string($myNewConnection, $email);
$email_code = mysqli_real_escape_string($myNewConnection, $email_code);
$query = mysqli_query($myNewConnection, "SELECT COUNT(`mem_id`) FROM `members` WHERE `mem_email` = '$email' AND `email_code` = '$email_code' AND `mem_emailactivated` = '0'");
$result = mysqli_num_rows($myNewConnection, $query);
echo $query;
exit();
if ($result == 1) {
$sql = "UPDATE `members` SET mem_emailactivated = 1 WHERE `mem_email` = '$email'";
$query = mysqli_query($myConnection, $sql) or die(mysql_error($myConnection));
return true;
} else {
return false;
}
}
如果我在我的代码中看到你回应了查询,我就会收到错误
Catchable fatal error: Object of class mysqli_result could not be converted to string in /homepages/24/d156351352/htdocs/test/storescripts/users.php on line 211
但是我很困惑因为我在函数或查询中没有使用mysqli_result,所以我不确定错误在哪里
答案 0 :(得分:0)
因为 SELECT查询会在result
中array
使用print_r
来查看结果
print_r($query);
答案 1 :(得分:-1)
我对mysqli和建立连接的位置感到困惑。我在mysqli_num_rows中有$ myNewConnection,它不应该在那里。看起来应该是这样的
function activate($email, $email_code) {
$myNewConnection = myConnection();
$email = mysqli_real_escape_string($myNewConnection, $email);
$email_code = mysqli_real_escape_string($myNewConnection, $email_code);
$query = mysqli_query($myNewConnection, "SELECT COUNT(`mem_id`) FROM `members` WHERE `mem_email` = '$email' AND `email_code` = '$email_code' AND `mem_emailactivated` = '0'");
$result = mysqli_num_rows($query);
print_r ($result);
exit();
if ($result == 1) {
$sql = "UPDATE `members` SET mem_emailactivated = 1 WHERE `mem_email` = '$email'";
$query = mysqli_query($myConnection, $sql) or die(mysql_error($myConnection));
return true;
} else {
return false;
}
}