Jump to content

Recommended Posts

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

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.