Jump to content

Modifying a DB Field using a Drop Down Box


ikon

Recommended Posts

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

Link to comment
Share on other sites

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.

 

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.