【发布时间】:2014-04-14 15:36:42
【问题描述】:
我试图从表单中获取输入并删除表数据,然后显示更新后的表,但我得到一个空白页,我不知道可能是什么问题,任何帮助都会得到这里是我的代码:
<html>
<body>
<?php
$mysqli = new mysqli("xxxxx", "xxxxxx", "xxxxx", "xxxxxx");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//----------------------------------------------------------------------------------//
$name = $_POST['Car_ID'];
if ($stmt = $mysqli->prepare("delete from CARS where name=?")) {
// Bind the variable to the parameter as a string.
$stmt->bind_param("s", $name);
// Execute the statement.
$stmt->execute();
echo "Deleted data successfully\n";
// Close the prepared statement.
$mysqli->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $db->prepare("SELECT id, Doors, TRANSMISSION, Fuel_type, Engine_Size, Total FROM CARS");
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
$doors=$row["Doors"];
$engine=$row["Engine_Size"];
$total=$row["Total"];
$trans=$row["Transmission"];
}
?>
<table>
<tr>
<td><?php echo $doors; ?></td>
<td><?php echo $engine; ?></td>
<td><?php echo $total; ?></td>
<td><?php echo $trans; ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
【问题讨论】:
-
将
}?>与} ?>隔开,并确保您的表单元素已命名。即:name="Car_ID" -
等一下...您正在将
mysqli_*与 PDO$mysqli->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);混合使用