I have a mysql database table with two fields: "key" and "value". I have created a form which lists every key with a text field with the value. I want to update the values for each key when the form is submitted. So I'm guessing I need some kind of loop to go through each key and update the value of each. Havn't done this before so would appriciate a bit of script to get the Update done all by one form (instead of updating each key separately). Thanks for any help with this
Is this a web based form or an application form? What are you using to code the form (PHP, ASP, etc...)? Will the form only allow them to change the value of the keys or will they be able to add a new key as well?
<?php # I suppose we already have a mysqli connection called $mysqli foreach ($_POST as $key => $value) { $pairs[] = $key . " = '" . $mysqli->real_escape_string($value) . "' "; } $update_string = implode(', ', $pairs); $query = 'UPDATE table SET ' . $update . ' WHERE ...'; # you should add your WHERE clause here $mysqli->query($query); ?> PHP: Did I earn some green?