如何在PHP中回显已准备好的sql语句的结果
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在PHP中回显已准备好的sql语句的结果相关的知识,希望对你有一定的参考价值。
我正在尝试使用准备好的语句从数据库中回显数据。我被困在实际循环显示结果上]
这里是代码:
$sql = "select fname,lname,email,address,suburb,state,postcode,phone from customer where id = ? ";
$stmt = $dbConn->prepare($sql);
$stmt->bind_param("s", $user);
$Stmt->execute();
$rs = $stmt->get_result();
<?php while($row = $stmt->fetch_assoc()) ?>
<h3> Your Current Details: </h3>
<p><strong>first name:</strong> <?php echo $row['fname'] ; ?></p>
<p><strong>last name:</strong> <?php echo $row['lname'] ; ?></p>
<p><strong>email:</strong> <?php echo $row['email'] ; ?></p>
<p><strong>post code:</strong> <?php echo $row['postcode'] ;?></p>
<p><strong>state:</strong> <?php echo $row ['state'] ; ?></p>
<p><strong>address:</strong> <?php echo $row ['address'] ; ?></p>
<p><strong>suburb:</strong> <?php echo $row ['suburb'] ;?></p>
<p><strong>phone:</strong> <?php echo $row ['phone'] ; ?></p>
</div>
我不熟悉使用预备陈述,使用预备陈述时,所有类似的帖子和在线帖子都显示了不同的方法。 (他们使用PDO)
答案
也许尝试这样的事情:
$sql = "select fname,lname,email,address,suburb,state,postcode,phone from customer where id = ? ";
$stmt = $dbConn->prepare($sql);
$stmt->bind_param("s", $user);
$stmt->execute();
$rs = $stmt->get_result();
echo "<h3> Your Current Details: </h3>";
while ($row = $stmt->fetch_assoc())
echo "<p><strong>first name:</strong>" . $row['fname'] . "</p>";
echo "<p><strong>last name:</strong>" . $row['lname'] . "</p>";
echo "<p><strong>email:</strong>" . $row['email'] . "</p>";
echo "<p><strong>post code:</strong>" . $row['postcode'] . "</p>";
echo "<p><strong>state:</strong>" . $row ['state'] . "</p>";
echo "<p><strong>address:</strong>" . $row ['address'] . "</p>";
echo "<p><strong>suburb:</strong>" . $row ['suburb'] . "</p>";
echo "<p><strong>phone:</strong>" . $row ['phone'] . "</p>";
echo "</div>";
以上是关于如何在PHP中回显已准备好的sql语句的结果的主要内容,如果未能解决你的问题,请参考以下文章
在 PHP 中使用准备好的语句/存储过程时如何保护自己免受 SQL 注入?