2013-05-07 5 views
1

이 질문은 이전에 물어 보았습니다. 많은 질문에 답을했으며 그 중 하나 인 answers now을 해결하려고했지만 다음 코드 조각에 대한 도움이 필요합니다. ,PDO 여러 레코드 업데이트

<?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); 
} 


?> 

난 당신이 자리 뭔가 알려 주시기 바랍니다 경우 실행 및 아무것도에 따라 오류가, MySQL의 테이블에 제출하지 얻을, 또는 이것에 대해 갈 수있는 더 좋은 방법이 있다면 당신은 튜토리얼을 향해 날 지점 수 필자는 아직 PDO 또는 다중 행 업데이트를 많이 사용하지 않았습니다.

미리 감사드립니다. 샘

:

print_r($STH->errorInfo()); 

출력했다 :

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) 
+0

는'합니까 인 print_r ($ STH-> errorInfo());'아무 것도 출력하지 않습니까? – Sam

+0

질문에 오류를 추가했습니다. 감사합니다. – Owen

답변

5

당신은 :description 후 여분의 쉼표를 가지고, 그것은해야한다 :

"UPDATE images 
SET title = :title, 
description = :description 
WHERE item_name = :item_name" 
+0

... 지금 당장 실망합니다.하지만 감사합니다. – Owen

+1

놓치기가 매우 쉽습니다! – Sam

관련 문제