ikon Posted March 15, 2008 Share Posted March 15, 2008 Hi All, I'm trying to change the Status of an Order in My Database from "New to Shipped" and according write it to the database, however - when i change the status currently and press "modify" its writing a blank field to the database? Here is my code for the drop down: <tr> <td class="label">Status</td> <td class="content"> <select name="cboOrderStatus" id="cboOrderStatus" class="box"> <?php echo $orderOption; ?> </select> <input name="btnModify" type="button" id="btnModify" value="Modify Status" class="box" onClick="modifyOrderStatus(<?php echo $orderId; ?>);"></td> </tr> Here is the source for the onClick function modifyOrderStatus(orderId) { statusList = window.document.frmOrder.cboOrderStatus; status = statusList.options[statusList.selectedIndex].value; window.location.href = 'processOrder.php?action=modify&oid=' + orderId + '&status=' + status; } and finally the write to the database: function modifyOrder() { if (!isset($_GET['oid']) || (int)$_GET['oid'] <= 0 || !isset($_GET['status']) || $_GET['status'] == '') { header('Location: index.php'); } $orderId = (int)$_GET['oid']; $status = $_GET['status']; $sql = "UPDATE tbl_order SET od_status = '$status', od_last_update = NOW() WHERE od_id = $orderId"; $result = dbQuery($sql); header("Location: index.php?view=list&status=$status"); } Many Many Thanks in Advance - i'd love to solve this Ikon Quote Link to comment Share on other sites More sharing options...
syed Posted March 15, 2008 Share Posted March 15, 2008 Hi Ikon Is it nessaccsry for you to us javascript to send your request? Quote Link to comment Share on other sites More sharing options...
ikon Posted March 15, 2008 Author Share Posted March 15, 2008 Not at all, but didn't know how to do it in PHP Quote Link to comment Share on other sites More sharing options...
syed Posted March 15, 2008 Share Posted March 15, 2008 Hi Ikon, you dont need to use javascript to send your request you can use the form tag to submit to a php page. Maybe the following code will share some light. Basic form Orders.php <form action="processorder.php" method="post"> product name<input type="text" name="proname"><br> <select name="orderstatus"> <option value="1">New</option> <option value="2">Shipped</option> </select> <input type="submit" name="modify" value="modify"> </form> processorder.php <?php if (isset($_REQUEST['modify'])){ $proname = $_REQUEST['proname']; $orderstatus = $_REQUEST['orderstatus']; if ($orderstatus == "1" ){ // update table, add New to table field }else{ // update table, add Shipped to table field } } ?> The above code is very basic but it demonstrated that you dont need to use javascript to send your request. And also your variables will not be shown in the url. So your users can not directly manipulate the variables in the url to casue an error. 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.