PHP MySQL Query 其中 x = $variable [已关闭]

2022-08-30 18:19:00

我有这个代码(我知道电子邮件已定义)

 <?php
$con=mysqli_connect($host,$user,$pass,$database);
 if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '.$email.'");

while($row = mysqli_fetch_array($result))
echo $row
?>

在我的MySQL数据库中,我有以下设置(表名是glogin_users)id电子邮件注释

我尝试从数据库中提取笔记文本,然后回显它,但它似乎没有回显任何东西。


答案 1

你现在正在做的是你在字符串上添加而不是连接。它应该是,.

$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '".$email."'");

或简称

$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '$email'");

答案 2
$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '".$email."'");
while($row = mysqli_fetch_array($result))
echo $row['note'];

推荐