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
https://forums.phpfreaks.com/topic/186130-postd-array-how-do-i-put-into-one-query/
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] . "'
  ";
}

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.