Jump to content

POST'd array, how do I put into one query!?


oni-kun

Recommended Posts

I have three arrays (of 43 elements each) sent from an html form:

done[], len[], and weight[]

 

How do I use a loop with insert for a query?.. for example:

foreach ($_POST['len'] as $v1) {
    echo $v1;
}

 

Will echo all of $_POST['len'][0-43], but how do I loop all three $_POST['done'][0-43], $_POST['weight'][0-43] arrays and put them into one INSERT query?! :confused:

 

In the SQL, my structure is "ID, done, length, weight" .. so I just need to somehow loop from 0-43 and insert each value.

Link to comment
Share on other sites

for ($i = 0; $i <=43; $i++) {
  $sql = "
    INSERT INTO (done,length,weight
    ) VALUES (
    '" . mysql_real_escape_string($_POST['done'][$i] ."',
    '" . mysql_real_escape_string($_POST['length'][$i] ."',
    '" . mysql_real_escape_string($_POST['weight'][$i] . "'
  ";
}

Link to comment
Share on other sites

Actually another question. Since I inserted all of them so the SQL table is filled now, I need them to update, not submit more:

 

"UPDATE personal SET weight = $_POST[weight][$i] WHERE ID = $i"

 

Will that work? An example is if I filled in another textbox, as they all will slowly be filled in over time. Just want them to update and populate slowly.

Link to comment
Share on other sites

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.