我想创建一个页面,我必须显示特定ID的记录,但它显示我的错误
注意:未定义的变量:第82行的mysqli。
致命错误:在第82行的非对象上调用成员函数query()。
这是程序的PHP代码。
$con=mysqli_connect("XXXX","XXXX","XXXX","XXXX");
if (mysqli_connect_errno())
echo "Failed to connect to MySQL: " . mysqli_connect_error();
$id = $_GET['id'];
$sql = "SELECT * FROM details WHERE cat_id = $id";
$result = mysqli_query($con,$sql); //line #82
$row = mysqli_fetch_array($result);
while($row = mysqli_fetch_array($result)){
$id = $row['cat_id'];
echo "<tr>";
echo "<td><a href='detail.php?id=$id' >" . $row['cat_name'] . "</a></td>";
echo "</tr>";
}
echo "<table>";
echo "<tr>";
echo "<th>name</th>";
echo "<th>address</th>";
echo "<th>phone</th>";
echo "<th>uan</th>";
echo "<th>location</th>";
echo "</tr>";
mysqli_close($con);
答案 0 :(得分:-1)
你没有像这样正确地循环记录:
$id = $_GET['id'];
$result = mysqli_query($con,"SELECT * FROM details WHERE cat_id = $id");
echo "<table>
<tr>
<th>name</th>
<th>address</th>
<th>phone</th>
<th>uan</th>
</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "<td>" . $row['uan'] . "</td>";
echo "</tr>";
}
答案 1 :(得分:-3)
$ con = mysqli_connect(“XXXX”,“XXXX”,“XXXX”,“XXXX”); if(mysqli_connect_errno()) {echo“无法连接到MySQL:”。 mysqli_connect_error();} $ id = $ _ GET ['id']; $ sql =“SELECT * FROM details WHERE cat_id = $ id”; $ result = mysqli_query($ con,$ sql); // line#82 $ row = mysqli_fetch_array($ result); echo“”; echo“”; echo“name”; echo“address”; echo“phone”; echo“uan”; echo“location”; echo“” ;而($行= mysqli_fetch_array($结果)) {$ id = $ row ['cat_id']; echo“”;回声“”。 $ row ['cat_name']。 “”; echo“”; } mysqli_close($ CON);