Hi All,
I am missing something obvious here. I have an array 'correct_answer_id' that returns ...
[correct_answer_id] => Array
(
[67] => 54
[68] => 60
)
from a print_r on my process page.
and then I do a foreach update loop...
mysql_select_db($dbname, $conn) or die (mysql_error());
$correct_answer_id = $_POST['correct_answer_id'];
foreach($correct_answer_id as $key => $value) {
$sql = "UPDATE questions ";
$sql .= "SET correct_answer_id='$value' ";
$sql .= "WHERE question_id='".$key."'";
echo $sql.'<br />';
printf ("Updated records: %d\n", mysql_affected_rows());
}
and here are the results...
UPDATE questions SET correct_answer_id='54' WHERE question_id='67'
Updated records: -1
UPDATE questions SET correct_answer_id='60' WHERE question_id='68'
Updated records: -1
but the database only shows record 68 being updated, 67 is still '0'. If it helps, record 68 is the last one in the database.
I am stumped.
Thanks in advance,
Don