Note that there are some explanatory texts on larger screens.

plurals
  1. POPDO Updating multiple records
    primarykey
    data
    text
    <p>I know this question has been asked before and I've gone through many of the answers and am working off one of those <A href="http://stackoverflow.com/questions/12043967/updating-multiple-mysql-table-columns-using-arrays-with-pdo">answers now</a>, however need some help with the following chunk of code.</p> <pre><code>&lt;?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-&gt;prepare($set_details); $i = 0; while($i &lt; $A) { $STH-&gt;bindParam(':title', $title[$i]); $STH-&gt;bindParam(':description', $description[$i]); $STH-&gt;bindParam(':item_name', $item_name[$i]); $STH-&gt;execute(); $i++; } } catch(PDOException $e) { echo "I'm sorry, but there was an error updating the database."; file_put_contents('PDOErrors.txt', $e-&gt;getMessage(), FILE_APPEND); } ?&gt; </code></pre> <p>I get no errors upon execution and nothing is submitted to the mysql table, if you spot something please let me know, or if there is a better way to go about this could you point me towards a tutorial, I haven't worked much with PDO or multiple row updates yet.</p> <p>Thanks in advance.</p> <p>To Sam:</p> <pre><code>print_r($STH-&gt;errorInfo()); </code></pre> <p>output was:</p> <pre><code>Array ( [0] =&gt; 42000 [1] =&gt; 1064 [2] =&gt; 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 ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload