我想弄清楚如何获得要发布的返回值。我的代码如下
<?php
$mysqli = new mysqli("localhost","user","password","db");
$lname=$_POST['lname'];
$query= "SELECT * FROM contacts WHERE lname = '".$lname."'";
$result = $mysqli->query($query);
if (!$result) {
printf("Query failed: %s\n", $mysqli->error);
exit;
}
return $result;
?>
我对php很新,但我正在做的是将一个名字发布到php文件,然后转到数据库,找到所有输入姓氏的值,然后我希望它返回值然后打印出来
答案 0 :(得分:0)
<?php
$mysqli = new mysqli("localhost","user","password","db");
$lname=$_POST['lname'];
$query= "SELECT * FROM contacts WHERE lname = '".$lname."'";
$result = $mysqli->query($query);
if (!$result) {
printf("Query failed: %s\n", $mysqli->error);
exit;
}
while ($contact = $result->fetch_assoc()) {
echo $contact['name']."<br>\n";
}
?>