PHP MySQL 查询其中 x = $variable
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15703608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP MySQL Query Where x = $variable
提问by user2224376
I have this code (I know that the email is defined)
我有这个代码(我知道电子邮件已定义)
<?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
?>
In my MySQL database I have the following setup (Table name is glogin_users) id email note
在我的 MySQL 数据库中,我有以下设置(表名是 glogin_users)id email note
I've tried extracting the note text from the database and then echo'ing it but it doesn't seem to echo anything.
我试过从数据库中提取笔记文本,然后回显它,但它似乎没有回显任何内容。
回答by John Woo
What you are doing right now is you are adding .
on the string and not concatenating. It should be,
您现在正在做的是.
在字符串上添加而不是连接。它应该是,
$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '".$email."'");
or simply
或者干脆
$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '$email'");
回答by Raheel Hasan
You have to do this to echo it:
你必须这样做才能回应它:
echo $row['note'];
(The data is coming as an array)
(数据以数组形式出现)
回答by Mucahit Kar
$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '".$email."'");
while($row = mysqli_fetch_array($result))
echo $row['note'];