我已经检查了连接及其工作。我也检查了数据库。有大约10条记录要显示。我使用了prepared语句,但是它返回一个空表。我一定在某个地方犯了错误,但找不到它。如果有人可以提供帮助,我将不胜感激。
<?php
$stmt=$mysqli->prepare("SELECT id,carreg,make,model,price,enginesize,gearbox,fueltype,noofdoors,image1 FROM cars");
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc())
{
?>
<tr>
<td><img src="<?php echo $upload_dir_car.$row['image1'] ?>" height="110" width ="150" img-responsive></td>
<td><?php echo $row['id'] ?></td>
<td><?php echo $row['carreg'] ?></td>
<td><?php echo $row['make'] ?></td>
<td><?php echo $row['model'] ?></td>
<td><?php echo $row['price'] ?></td>
<td><?php echo $row['enginesize'] ?></td>
<td><?php echo $row['gearbox'] ?></td>
<td><?php echo $row['fueltype'] ?></td>
<td><?php echo $row['noofdoors'] ?></td>
<td>
<a class="btn btn-primary" href="car_edit.php?id=<?php echo $row['id'] ?>">
<i class="fas fa-edit fa-xs"></i>
</a>
<a class="btn btn-danger" href="car_manage.php?delete=<?php echo $row['id'] ?>" onclick="return confirm('Are you sure to delete this record?')">
<i class="fas fa-trash-alt fa-xs"></i>
</a>
</td>
</tr>
<?php
}
$stmt->close();
?>
改正像这样的东西:
$sql = "SELECT id,carreg,make,model,price,enginesize,gearbox,fueltype,noofdoors,image1 FROM cars";
$result = $mysqli -> query($sql);
while($row = $result->fetch_assoc()){
//your codes
}
您不需要prepare()函数。