php - 严格标准 : only variables should be passed by reference - why does this still work and how can I correct it?

标签 php mysql sql

在提交用户详细信息后,我正在尝试查询数据库以检查电子邮件是否已注册。

但是,我收到以下代码(摘录)的“严格标准:只有变量应通过引用传递”错误:

} else  if (isset($_POST['srSubmit']) && $_POST['srEmail']) {

    //check if email already taken
    if ($stmtreg = $mysqli->prepare("SELECT user_email FROM users WHERE user_email = ?")) {
        $stmtreg->bind_param("s", strtolower($_POST['srEmail']));
        $stmtreg->execute();
        $stmtreg->store_result();
        $num_rows = $stmtreg->num_rows();
        $stmtreg->bind_result($email);
        $stmtreg->fetch();
        $stmtreg->close();
    }

我有两个问题:i) 为什么脚本仍然有效,即使有这个错误? ii) 是什么原因造成的,我该如何解决?

谢谢

最佳答案

strtolower($_POST['srEmail']) 设置一个临时变量,类似于:

$email = strtolower($_POST['srEmail']);

然后将 $email 传递给您的 bind_param。即使 strtolower() 返回一个字符串,PDO 也不能引用它,因为它不是一个变量。

关于php - 严格标准 : only variables should be passed by reference - why does this still work and how can I correct it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17886489/

相关文章:

php - 在 Laravel Eloquent 中查询只有日期的日期时间字段

javascript - 将 Javascript 代码转换为 php

mysql - 如何从 iOS 应用程序访问服务器 MySQL 数据库

mysql - 将 @jointable 与所有非唯一列一起使用

python - 尝试 INSERT 到 MySQL 时不断出现错误

mysql - 查找使用 SQL 接受的 friend 请求的分数?

php - 将日期时间转换为时间戳 php

php - 将多个动态文本框放入 JavaScript 数组中

mysql - 获取至少有3个项目的所有账户

mysql - 如何使无引号、逗号分隔的 ID 列表适用于 MySQL 中的 IN 子句