PDO更新多条记录

Owe*_*wen 1 php mysql pdo sql-update

我知道之前已经问过这个问题并且我已经完成了许多答案,现在正在处理其中一个答案,但是需要一些帮助来处理以下代码.

<?php

$title = $_POST['title'];
$description = $_POST['description'];
$item_name = $_POST['item_name'];

$A = count($item_name);

include ("connection.php");

try {

    $set_details = "UPDATE images
                    SET title = :title,
                    description = :description,
                    WHERE item_name = :item_name";


$STH = $conn->prepare($set_details);

    $i = 0;
    while($i < $A) {
        $STH->bindParam(':title', $title[$i]);
        $STH->bindParam(':description', $description[$i]);
        $STH->bindParam(':item_name', $item_name[$i]);
        $STH->execute();
        $i++;
    }
}
catch(PDOException $e) {  
    echo "I'm sorry, but there was an error updating the database.";  
    file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}


?>
Run Code Online (Sandbox Code Playgroud)

执行时我没有错误,没有提交到mysql表,如果你发现了什么请告诉我,或者如果有更好的方法可以解决这个问题,你可以指点我一个教程,我没有多少工作PDO或多行更新.

提前致谢.

致山姆:

print_r($STH->errorInfo());
Run Code Online (Sandbox Code Playgroud)

输出是:

Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE item_name = '27'' at line 4 )
Run Code Online (Sandbox Code Playgroud)

Sam*_*Sam 5

之后你有一个额外的逗号:description,它应该是:

"UPDATE images
 SET title = :title,
 description = :description
 WHERE item_name = :item_name"
Run Code Online (Sandbox Code Playgroud)