抓住这个,我有一个表格显示表格中的所有行,整个表格将在表格提交上更新。上下文是这是网站导航。
错误: 致命错误:带有消息'SQLSTATE [42000]的未捕获异常'PDOException':语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MySQL服务器版本相对应的手册,以便在'order ='附近使用正确的语法1'WHERE ID ='1'在1号行的'LIMIT 1'(路径)堆栈跟踪:#0(路径):PDOStatement - >在第65行(路径)中抛出执行(数组)#1 {main}
表格:
<form action="<?=$PHP_SELF?>" method="POST">
<?php
$navstmt = $dbh->prepare("SELECT *
FROM `navlinks`
ORDER BY `order` ASC
LIMIT 0 , 30 ");
$navstmt->execute();
$result = $navstmt->fetchAll();
echo "<table width='500px'><tr><td><b>ID</b></td><td><b>Display Title</b></td><td> <b>Page Name (URL)</b></td><td><b>Order</b></td><td><b>Delete</b></td></tr>";
foreach($result as $row)
{
echo '<tr><td><input type="text" name="ID[]" size="4" value="'.$row['ID'] . '"></td><td><input type="text" name="title[]" value="'.$row['title'] . '"></td><td><input type="text" name="url[]" value="'.$row['url'] . '"></td><td><input type="text" name="order[]" size="4" value="'.$row['order'] . '"><td><a href="#"><img src="img/cancel.gif" border="0"></a></td></tr>';
}
echo '</table>';
?>
<p><input type="submit" name="button" value="Save Changes"></p>
保存到数据库:
<?php
if($_POST['title']){
$size = count($_POST['title']);
$size = count($_POST['url']);
$size = count($_POST['order']);
$i = 0;
while ($i < $size) {
$title = $_POST['title'][$i];
$url = $_POST['url'][$i];
$id = $_POST['ID'][$i];
$order = $_POST['order'][$i];
$sql = "UPDATE navlinks SET title = :title, url = :url, order = :order WHERE ID = :id LIMIT 1";
$q = $dbh->prepare($sql);
$q->execute(array(':title' => $title, ':url' => $url, ':order' => $order, ':id' => $id));
echo '<div class="alert alert-success"><b>All done!</b> The navigation has been updated.</div>';
++$i;
}
}
?>
我确信这可能是非常明显的,但任何帮助都会非常感激!