Jump to content

multiple inserts in mysql


sheriff

Recommended Posts

hi all ...

 

I have a long list generated from a while loop.

 

---------------------------------------

|ID  |Name      | Description              |

---------------------------------------

|22  |product22 | desc22                    |

|56  |product56 | desc56                    |

|64  |product64 | desc64                    |

----------------------------------------

 

it's possible to insert this list in a mysql database ?

 

Thanks !

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/52938-multiple-inserts-in-mysql/
Share on other sites

ok jitesh :) .. thanks

 

now, please tell me how can I apply this to my situation :D

 

This is the page where show up the generated product list.

<form action="insert_order.php" method="POST">
<table border="1">
<tr>
	<td>Client
	<td>
		<?php
			$query = "select comp_id, comp_name from client";
			$result = mysql_query($query);

			print '<select name="cmd_comp" style="background-color: #F89800; border: 1px solid #475558">';
				while ($row = mysql_fetch_array($result)) {
			print '<option value="'.$row[comp_name].'">'.$row[comp_name];
				}
			print '</select>';
		?><br><a href="add_client.php" style="text-decoration: none"><font size="2" color="#000000">Adauga clinet</font></a>
</table>

<br>
<table bgcolor="#DDDAD4" cellpadding="1" cellspacing="1">
<tr>
<td width="150" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Nume</strong></font></td>
    <td width="50" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Descriere</strong></font></td>
    <td width="50" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Buc</strong></font></td>
</tr>
<?php

if(isset($_POST)){
          if(count($_POST['check'])){
            $list_selected = "";
            foreach($_POST['check'] as $key => $ids){
                   $list_selected .= $ids .",";
            }
            $list_selected = substr($list_selected,0,strlen($list_selected)-1);
            // This will give ur selected ids like this 100,203,125,123
          }else{
            $list_selected = "-1";
          }
}

$query = "select * from products WHERE pr_id IN (".$list_selected.")";

$result = mysql_query($query);
$count = mysql_num_rows($result);

$color1 = "#DDDAD4";
$color2 = "#DDD7CC";
$row_count = 0;

while($row = mysql_fetch_array( $result )) {
$row_color = ($row_count % 2) ? $color1 : $color2;

$id = $row['pr_id'];
$name = $row['pr_name'];
$desc = $row['pr_desc'];
$um = $row['pr_um'];
?>
<tr>
<td><input type="hidden" name="cmd_id"><input type="hidden" name="pr_id" value="<?php echo $id; ?>">
	<input type="text" name="pr_name" value="<?php echo $name; ?>" size="30"></td>
    <td><font size="3"><input name="pr_desc" type="text" name="pr_desc" value="<?php echo $desc; ?>" size="50"></td>
    <td align="center"><input name="pr_qty" type="text" name="pr_qty[]" size="5"></font></td>
</tr>
<?php
$row_count++;
}
?>
</table>
<br>
<input type="submit" name="submit" value="Adauga">
</form>

 

and this is the insert query!

mysql_query("INSERT INTO comenzi (cmd_id, cmd_comp, pr_id, pr_name, pr_desc, pr_qty, cmd_date, cmd_exp) VALUES (NULL , '$_POST[cmd_comp]', '$_POST[pr_id]', '$_POST[pr_name]', '$_POST[pr_desc]', '$_POST[pr_qty]', '$today', '$_POST[cmd_exp]')") or die(mysql_error());

 

you see, there is many <inpu type="text"> witha a name="something" ... i think it must be something[] .. but this is an array, and when i push the button to add it to mysql, only the last item will be inserted in the database. :(

 

I want to make something like a shopping cart, but without payment, checkout. I want to enter my customer orders and they products in a database.

 

thanks for help

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.