samtwilliams Posted July 16, 2009 Share Posted July 16, 2009 Hi all, I am stuck and a little lost trying to use a form to post multiple values to update a mysql database. I have created a form which is generated from a list of rows out of the database which allows a user to update a certain column, i am just stuck with how i actually peform the update with the array. My Form code is below; <form name="settings" method="post" action="exec.php"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <?PHP while ($row = mysql_fetch_assoc($result)){ ?> <tr> <td><?PHP echo $row['name']; ?></td> <td><input name="<?PHP echo $row['name']; ?>" type="text" id="<?PHP echo $row['name']; ?>" value="<?PHP echo $row['value']; ?>" size="100"> </td> <td><?PHP echo $row['help']; ?></td> </tr> <?PHP } ?> <tr> <td> </td> <td> </td> <td> </td> </tr> </table> <input type="submit" name="Submit" id="Submit" value="Submit"> </form> I have checked what the array looks like and it looks like this part is working fine, the array looks like; Array ( [global_title_index] => a [global_logo_title] => b [global_logo_text] => c [global_webmaster_link] => d [global_footer_webinfotop] => e [submit] => Submit ) So all i am trying to achieve is to insert this data into my database; ------------------------------- column names: name | value global_title_index | a global_title_title | b Hope someone understands what i am trying to achieve, and hope they can help Sam Quote Link to comment https://forums.phpfreaks.com/topic/166245-an-array-generated-by-a-form-to-update-mysql-database/ Share on other sites More sharing options...
samtwilliams Posted July 16, 2009 Author Share Posted July 16, 2009 I have been playign with this but not sure if i am on the right track? Any ideas anyone? function mysql_update_array($table, $data, $id_field, $id_value) { foreach ($data as $field=>$value) { $fields[] = sprintf("`%s` = '%s'", $field, mysql_real_escape_string($value)); } $field_list = join(',', $fields); $query = sprintf("UPDATE `%s` SET %s WHERE `%s` = %s", $table, $field_list, $id_field, intval($id_value)); return $query; } mysql_update_array(globals, $_POST, name, $_POST); Quote Link to comment https://forums.phpfreaks.com/topic/166245-an-array-generated-by-a-form-to-update-mysql-database/#findComment-876722 Share on other sites More sharing options...
samtwilliams Posted July 16, 2009 Author Share Posted July 16, 2009 Tried a few thinds now and completly lost, anyone help please. Thanks Sam Quote Link to comment https://forums.phpfreaks.com/topic/166245-an-array-generated-by-a-form-to-update-mysql-database/#findComment-876754 Share on other sites More sharing options...
Zane Posted July 16, 2009 Share Posted July 16, 2009 show us all the code...meaning...show the query and connection and such along with it Quote Link to comment https://forums.phpfreaks.com/topic/166245-an-array-generated-by-a-form-to-update-mysql-database/#findComment-876769 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.