anser316 Posted March 30, 2008 Share Posted March 30, 2008 Hi, im having a problem with my code. I am trying to build an ordering system, where it shows the products that need to be ordered, which i have done. It should allow you to tick the products you want to order, which i have also done. The rows selected should then send to another form, and show its details. On this form it should also change one of the the attributes in the table called 'status' from NO STATUS to ORDERED. The problem i am having, is that on the second page, it only shows the drug_id, not the others, i think its because its the value of the checked box. Hence, im also having difficulty with looping an update statement, but il never get that to work until i get the first part right. This code is for the first form - order $result2 =mysql_query("SELECT i.drug_id,i.branch_id, d.drug_name,i.total_stock,i.reorder_level, s.supplier_name FROM drugs d, supplier s, branch_items i,branch b WHERE d.supplier_id=s.supplier_id AND d.drug_id=i.drug_id AND b.branch_id=i.branch_id AND i.total_stock<=i.reorder_level ORDER BY total_stock"); echo "<BR><br>"; echo "<b>Minimum Stock Level Met - Reorder Needed</b><p>"; echo "<form action= conorder.php method=POST>"; echo "<table border='1'>"; echo "<tr> <th>DRUG ID</th> <th>Branch ID</th><th>DRUG NAME</th><th>STOCK</th><th>REORDER LEVEL</th><th>SUPPLIER</th></tr>"; while($row = mysql_fetch_array( $result2 )) { echo "<tr><td>"; echo $row['drug_id']; echo "</td><td>"; echo $row['branch_id']; echo "</td><td>"; echo $row['drug_name']; echo "</td><td>"; echo $row['total_stock']; echo "</td><td>"; echo $row['reorder_level']; echo "</td><td>"; echo $row['supplier_name']; echo "</td><td>"; echo "<input type=checkbox name=ticked[] value='{$row['drug_id']}'>"; echo "</td></tr>"; } echo "</table>"; echo "<input type =submit value= Submit>"; echo "<input type = reset>"; echo "</form>"; This code is for the second form, that retrieves the data - conorder if (isset($_POST['ticked'])){ echo "chosen<br>"; echo "<table border='1'>"; echo "<tr> <th>DRUG ID</th> <th>Branch ID</th><th>DRUG NAME</th> <th>BRANCH</th><th>Reorder Level</th><th>Reorder Quantity</th><th>Total Stock</th><th>Status</th></tr>"; foreach ($_POST['ticked'] as $drug_id){ echo "<tr><td>"; echo $drug_id; echo "</td><td>"; echo "$_POST[branch_id]"; echo "</td><td>"; echo $_POST[drug_name]; echo "</td><td>"; echo $_POST[$branch_details]; echo "</td><td>"; echo $_POST[$reorder_level]; echo "</td><td>"; echo $_POST[$reorder_quantity]; echo "</td><td>"; echo $_POST[$total_stock]; echo "</td><td>"; echo $_POST[$status]; echo "</td></tr>"; } } if (isset($_POST['ticked'])){ foreach ($_POST['ticked'] as $drug_id){ $result =mysql_query("UPDATE branch_items b SET status =ORDERED WHERE drug_id=".$_POST [drug_id]." AND branch_id=".$_POST [branch_id].""); }} Quote Link to comment 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.