我正在尝试创建一个系统,选择 username2 等于变量的所有行,但不明白为什么这不起作用。我对 MySQL 还很陌生。
这不起作用:
$sql = "SELECT username2, petbreed, petcost, pettype FROM pets WHERE username2
= " + $first_name;
这也不是:
$sql = "SELECT username2, petbreed, petcost, pettype FROM pets WHERE
username2 = '" + $first_name + "'";
但这确实:
$sql = "SELECT username2, petbreed, petcost, pettype FROM pets WHERE
username2 = 'JohnDoe'";
感谢您花时间阅读本文。
最佳答案
你可以这样写:
$sql = "从 pets WHERE 中选择 username2、petbreed、petcost、pettype
用户名2 = '$first_name'"
.
在整个表达式周围使用双引号,在变量周围使用单引号。
+
不是 PHP 中的连接符号。点 .
是。
关于php - 选择值等于变量 MySQL 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48736821/