Jump to content

[SOLVED] Help! mysql insert multiple items into table from form


krv

Recommended Posts

Hello I am trying to insert multiple line items into a table and can only seem to get 1 item in a time my array is failing. Below is my example of what I want it to do. Any help is appreciated. Thanks!

 

<?php

// something i tired

$query = "INSERT INTO table(part,qty,qty2)VALUES";

       

        foreach ($_POST[part] as $key) {

        $query .= "('$key','$_POST[qty][$key]','$_POST[qty2][$key]')";

        $result = mysql_query($query)or die(mysql_error());

 

if(isset($_POST['add'])){

// need to be able to insert all values shown above using a loop and array

$sql = "INSERT INTO table (part,qty,qty2) VALUES ()";

$result = mysql_query($sql)or die(mysql_error());

 

}

?>

<form method="POST">

<table>

<tr>

<td><input type="text" name="part[]"></td>

<td><input type="text" name="qty[]"></td>

<td><input type="text" name="qty2[]"></td>

</tr>

<tr>

<td><input type="text" name="part[]"></td>

<td><input type="text" name="qty[]"></td>

<td><input type="text" name="qty2[]"></td>

</tr>

<tr>

<td><input type="text" name="part[]"></td>

<td><input type="text" name="qty[]"></td>

<td><input type="text" name="qty2[]"></td>

</tr>

<tr>

<td><input type="text" name="part[]"></td>

<td><input type="text" name="qty[]"></td>

<td><input type="text" name="qty2[]"></td>

</tr>

<tr>

<td><input type="text" name="part[]"></td>

<td><input type="text" name="qty[]"></td>

<td><input type="text" name="qty2[]"></td>

</tr>

<tr>

<td><input type="submit" name="submit" value="add"></td>

</tr>

</table>

</form>

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.