Web Hosting Talk







View Full Version : How to update multiple rows in a database with one form?


JTM
12-21-2004, 10:12 PM
I have a list of IDs that each have text boxes so I can change the order of a rating (similar to netflix's movie queue). I'm having problems getting it to detect the ID of each of the movie names since it needs to be like id[id] instead of just id for the field name. It seems to be returning the value of the rating correctly, but it's showing Array for the id field. Can someone tell me what I'm doing wrong?

This is how I have each textbox loading:

<input type="hidden" name="id[{ID}]" id="id[{ID}]" value="{ID}" /><input type="text" name="rating[{ID}]" id="rating[{ID}]" value="{RATING}" />

foreach ($rating as $it=>$value) {
mysql_query("UPDATE movies SET rating='".$value."' WHERE id='".$id."'") or die(mysql_error);
}

OxnardMontalvo
12-22-2004, 01:50 PM
Personally, it looks like a typo in your foreach. you are setting $it but using $id.

=C=