gpt4 book ai didi

php - mysqli_query 不显示任何结果

转载 作者:行者123 更新时间:2023-11-29 23:17:28 26 4
gpt4 key购买 nike

我想从 MySQL 表中检索与特定电子邮件匹配的数据。有 2 条记录与此电子邮件相关,但我的屏幕上没有打印任何内容。

<?php

$conn = mysqli_connect('localhost', 'root', '', 'testdrive');


$sql = mysqli_query($conn,
'SELECT * FROM products_bought
where email = "'.mysqli_real_escape_string($conn, "a@gmail.com").'"'
);
while($row = mysqli_fetch_array($sql)){
$fullname = $row['fullname'];
?>
<p><?php echo $fullname; ?></p>
<?php
}

?>

最佳答案

我不知道问题从何而来,但我想帮助你一点:

<?php
$conn = mysqli_connect('localhost', 'root', '', 'testdrive');
$sql = mysqli_query($conn,'SELECT * FROM products_bought
where email = "'.mysqli_real_escape_string($conn, "a@gmail.com").'"');

if($sql->num_rows > 0){ // Check existence of the data that received
while($row = mysqli_fetch_array($sql)){
$fullname = $row['fullname'];
echo "<p>".$fullname."</p>"; // Why just echoing it in one <?PHP ?>
}
} else {
// If no data sent. then check your db, cause the problems was in your db
}
?>

关于php - mysqli_query 不显示任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27644557/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com