$sql1 = 'SELECT * FROM user WHERE username LIKE "test"';
但是当我使用这样的变量时,它会出错:
$username = $_POST["username"];
$sql1 = 'SELECT * FROM user WHERE username LIKE'.$username;
错误:
致命错误:在布尔值...
上调用成员函数fetch_assoc()
var_dump
的{p> $username
给出了:
string(4) "test"
感谢您的帮助!
到目前为止的完整代码:
$username = $_POST["username"];
var_dump($username);
include 'data.php';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql1 = 'SELECT * FROM user WHERE username = "'.$username.'"';
$result1 = $conn->query($sql1);
$row1 = $result1->fetch_assoc();
echo $row1["ID"];
答案 0 :(得分:1)
感谢lakhvir kumar!我使用了两次变量名,也有一些语法错误。
更改了$ username,现在可以正常工作..