I have an application that is driving me nuts. I have a form that is dynamically created from a query, it works fine. The user may enter a quantity from a . Once they click the button to post, I want the results to be entered into a table. There are 7 columns of data, the number of rows will be determined by the number the user chooses.
I have been unable to get this to work completely.
I have tried this:
[php]$query_Recordset3 = " INSERT INTO temporder ( qnt, prod_id) VALUES ";
foreach($_POST[‘qnt’] AS $prod_id => $qnt )
{
mysql_real_escape_string($query_Recordset3);
$query_Recordset3 .= “(’”.$qnt."’,’".$prod_id."’),";
}
$query_Recordset3 = substr($query_Recordset3,0,-1); // get rid of trailing comma, since we cant use implode
$Recordset3 = mysql_query($query_Recordset3, $szabo) or die(mysql_error()); [/php]
This works with inserting 2 columns, but I have been unable to get more than two. I have added additional foreach() lines, but they get jumbled.
Next I moved on to this:
[php]$qnt=$_POST[‘qnt’];
$prod_id=$_POST[‘prod_id’];
$ptype=$_POST[‘ptype’];
$git=mysql_query(“SELECT prod_id FROM garyco WHERE prod_id>=‘1’”);
$getf = mysql_fetch_array($git);
do{
echo $getf[‘prod_id’].’,’;
}
while ($getf = mysql_fetch_array($git));
$q=mysql_num_rows($git);
$qi="INSERT INTO temporder (qnt, prod_id, ptype) VALUES";
for( $i=0; $i<count($q); $i++); {
$qi .= "('".$qnt.'", "'.$prod_id.'", "'.$ptype."')$i,";
}
$qi= substr($qi, 0, -1);
$result=mysql_query($qi, $szabo);[/php]
I do not get any data inserted with the for() script.
Can someone please point out where I am going wrong.
Thank you
Gary