diginamics Posted January 27, 2011 Share Posted January 27, 2011 First page adds a new job number, then the order page loaded with the job number id as a get id. Basically there is a while loop in the order page which shows products/services client can order and he chooses what he requires 'one or eight services' (8 in total) and some other variables like date of order and client name etc. Here is the order item code The first sql statement executes fine, but in the second sql query nothing happens $sql="insert into job_order(order_num,order_date,order_customer_id, order_remarks) values(".$_GET['id'].",NOW(),".$_POST['companyBox'].",'".$_POST['remarkBox']."');"; $res=mysql_query($sql); $id=mysql_insert_id(); foreach($_POST as $key => $value) { if(!empty($value)) { $key.' => '.trim(strip_tags($value)); $order="INSERT INTO orderprod (order_num,prod_id,order_amount,teeth_amount) VALUES ('$_GET[id]','$value','$value','$value');"; $orderres=mysql_query($order) or die(mysql_error()); } }?>$sql="insert into job_order(order_num,order_date,order_customer_id, order_remarks) values(".$_GET['id'].",NOW(),".$_POST['companyBox'].",'".$_POST['remarkBox']."');"; $res=mysql_query($sql); $id=mysql_insert_id(); foreach($_POST as $key => $value) { if(!empty($value)) { $key.' => '.trim(strip_tags($value)); $order="INSERT INTO orderprod (order_num,prod_id,order_amount,teeth_amount) VALUES ('$_GET[id]','$value','$value','$value');"; $orderres=mysql_query($order) or die(mysql_error()); } } ?> ============= This is the formI have removed parts which are irrelevant. Please note that dateBox and companyBox are not required to be looping as they are only for first table, echo "<form action=".$config_basedir."./vieworder.php?id=".$_GET['id']." name=form1 method=post>";?><table><tr><td><h4>JOB ORDER</H4></TD><TD></TD></TR><TR><TD>ORDER NUMBER</TD><TD><?PHP ECHO $_GET['id'] ?></td></tr><tr><td>ORDER DATE</td><td><input type=text name=dateBox></td></tr> <tr><td>COMPANY NAME</td><td><?PHP$sql="select * from customers";$res=mysql_query($sql);echo "<select name=companyBox><option value=''>Please select</option>";WHILE($fetch=mysql_fetch_assoc($res)){ echo "<option value='".$fetch['id']."'>".$fetch['cust_name']."</option>";} echo "</select>"; echo "</td></tr>"; ?> </table> <table><tr><th>ITEM</th><th>QUANTITY</th><th>N0. of Teeths</th></tr><tr><?PHP$sql="select * from products";$res=mysql_query($sql); WHILE($fetch=mysql_fetch_assoc($res)){ echo "<td><input type=text name=desBox value='".$fetch['prod_id']."'>".$fetch['prod_name']."</td><td><input type=text name=quantBox></td><td><input type=text name=teethBox></td>";echo "</tr>";}echo "</table>";?>echo "<form action=".$config_basedir."./vieworder.php?id=".$_GET['id']." name=form1 method=post>"; ?> <table> <tr> <td><h4>JOB ORDER</H4></TD><TD></TD> </TR> <TR> <TD>ORDER NUMBER</TD><TD><?PHP ECHO $_GET['id'] ?></td> </tr> <tr> <td>ORDER DATE</td><td><input type=text name=dateBox></td> </tr> <tr> <td>COMPANY NAME</td><td> <?PHP $sql="select * from customers"; $res=mysql_query($sql); echo "<select name=companyBox><option value=''>Please select</option>"; WHILE($fetch=mysql_fetch_assoc($res)){ echo "<option value='".$fetch['id']."'>".$fetch['cust_name']."</option>";} echo "</select>"; echo "</td></tr>"; ?> </table> <table> <tr> <th>ITEM</th><th>QUANTITY</th><th>N0. of Teeths</th> </tr> <tr> <?PHP $sql="select * from products"; $res=mysql_query($sql); WHILE($fetch=mysql_fetch_assoc($res)){ echo "<td><input type=text name=desBox value='".$fetch['prod_id']."'>".$fetch['prod_name']."</td> <td><input type=text name=quantBox></td> <td><input type=text name=teethBox></td>"; echo "</tr>";} echo "</table>"; ?> HERE IS THE IMAGE showing the populated services. http://dubads.com/images/order.jpg Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/ Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 i would check to see if the query runs, and display the error if not. this is the way i do it. $res = mysql_query($sql) or die(mysql_error() . " IN $sql"); Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/#findComment-1166048 Share on other sites More sharing options...
diginamics Posted January 27, 2011 Author Share Posted January 27, 2011 I have already tried it, it shows incorrect int value for prod_id and if I echo value it does not show all the entries as shown in the image url attached. Also, the second table is all int. I just need a fix to while loop arrays. As I said earlier values are inserted in table 1 (joborder) correctly, I am having problem inserting array values in the 2nd table (orderprod) Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/#findComment-1166053 Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 what do you mean by "in the second sql query nothing happens"? is that code ever reached? and this does nothing. what should it be doing? $key.' => '.trim(strip_tags($value)); // does nothing. Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/#findComment-1166058 Share on other sites More sharing options...
diginamics Posted January 27, 2011 Author Share Posted January 27, 2011 The first query inserts values in table job_oder The second query is supposed to insert array data into table 'orderprod' sql="insert into job_order(order_num,order_date,order_customer_id, order_remarks) values(".$_GET['id'].",NOW(),".$_POST['companyBox'].",'".$_POST['remarkBox']."');"; $res=mysql_query($sql); AND THE SECOND ONE $order="INSERT INTO orderprod (order_num,prod_id,order_amount,teeth_amount) VALUES ('$_GET[id]','$value','$value','$value');"; $orderres=mysql_query($order) or die(mysql_error()); and you are right this ($key.' => '.trim(strip_tags($value)); ) does not do anything. I had removed it ealier Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/#findComment-1166062 Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 so is no record getting inserted? or is there an error? or neither? if neither is happening, then $value must be empty. remember, empty can also be a 0 or empty string, "". http://php.net/manual/en/function.empty.php Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/#findComment-1166075 Share on other sites More sharing options...
diginamics Posted January 27, 2011 Author Share Posted January 27, 2011 Have a look at this image and you will understand what I am trying to get out of this form. it is only inserting one value in the 2nd table (orderprod) where it should insert all the enteries that are filled. Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/#findComment-1166095 Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 referring to the 2nd query only: so is no record getting inserted? or is there an error? or neither? if neither is happening, then $value must be empty. remember, empty can also be a 0 or empty string, "". http://php.net/manual/en/function.empty.php Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/#findComment-1166103 Share on other sites More sharing options...
diginamics Posted January 27, 2011 Author Share Posted January 27, 2011 I just posted an image and it is showing that there is one entry instead of three. Have a look at the image and see the red highlighted area Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/#findComment-1166124 Share on other sites More sharing options...
sasa Posted January 27, 2011 Share Posted January 27, 2011 change your form to WHILE($fetch=mysql_fetch_assoc($res)){ echo "<td><input type=text name=desBox[] value='".$fetch['prod_id']."'>".$fetch['prod_name']."</td> <td><input type=text name=quantBox[]></td> <td><input type=text name=teethBox[]></td>"; echo "</tr>";} echo "</table>"; and on submitr page do ... foreach($-POST['desBox'] as $key = $prod_id){ $quant = $_POST['quantBox'][$key]; $teeth = $_POST['teethBox'][$key]; if($quant > 0){ //insert in db } } .... Quote Link to comment https://forums.phpfreaks.com/topic/225862-insert-form-variable-in-first-table-and-while-loop-variables-array-in-the-2nd/#findComment-1166242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.