Jump to content

insert form variable in first table and while loop variables (array) in the 2nd


diginamics

Recommended Posts

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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
    }
}
....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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