Hi All --
Following a printed example in New Rider's MySQL book, I've newbie-hacked my way to the following script. Unfortunately, it is not working and I can't figure out why.
Here's the setup: from an php page displaying DB contents and form blanks, you can insert new values into a field called status. The status field is associated with a unique identifier, 'id'. Here is how the status blank is created:
$change_stat = sprintf ("<INPUT TYPE=\"text\" NAME=\"status[%s]\"", $row["id"]);
$change_stat .= sprintf (" VALUE=\"%s\" DEFAULT=\"%s\" SIZE=\"5\"><BR>", $row["status"], $row["status"]);
I enter the new data and hit the 'submit' button on the html form. In theory (and according to New Riders), PHP stuffs everything into an array, here called $status, and passes it to the next sub. Now things go bad.
PHP begins inserting the new data into the DB with using a while/each line, but goes belly-up after the first line. PHP complains 'data passed to "each" is not an array or object'. Here is the insertion code:
while (list ($id, $nu_status) = each ($status))
{
$query = "UPDATE result SET status=\"$nu_status\" WHERE id = $id";
if (!mysql_query ($query))
die ("Sorry, data entry failed for id # $id. Please check your entry");
}
What is going wrong? It inserts the first row of data without a hitch, but nothing after...
Now, I'm sure I botched this someplace, but I can't peg it down. Hope somebody can help... my third cup coffee didn't. =] I'd be happy to give more details if needed.
regards,
-pt