Jump to content

If / Then question


lansing

Recommended Posts

I have a drop down menu that updates the status of a record in a MySQL db. I have 4 statuses...[i]Received[/i], [i]Pending[/i], [i]Filled[/i], & [i]Canceled[/i]. I am posting the form to [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]<?php $_SERVER['PHP_SELF'] ?>[!--colorc--][/span][!--/colorc--]. I will post the source code below. I need a couple of things to happen when I click the save button.

If the option that I chose is the status of [i]Filled[/i] then I need to be able to enter a tracking number in a text field & after I enter that number then it perform the MySQL record update with the tracking number. Secondly if I choose the status of [i]Filled[/i] I need to update the order filled column in the db which is DATE/TIME format.

If the option that I chose is the status of [i]Cacnelled[/i] then I need to be able to enter the reason for canceling the order in a text field & after I enter that number then it perform the MySQL record update with the cancellation reason.

[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php require("../vars.php"); ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo "$popup_status" ?></title>
</head>
<body>
    <form method="post" name="status_update" action="<?php $_SERVER['PHP_SELF'] ?>">
        <fieldset>
        <legend> Update Order Status </legend>
<p align="center">
        <label for="status">Status:<select name="status" id="status">
        <option selected value="">Choose status...
        <option value="Received">Received</option>
        <option value="Pending">Pending</option>
        <option value="Filled">Filled</option>
        <option value="Canceled">Canceled</option>
        </select></label><br /><br>
        <input type="submit" value="Save" name="save" class="submit" />
        </fieldset>
    </form>
<?php
if($_POST['save'])
{
    require("../cdb.php");

    $status = $_POST['status'];
    $now = date("Y-m-d H:i:s");
    $id = $_REQUEST['id'];

    $status_update = ("UPDATE $orders SET order_status = '$status', order_modified = '$now' WHERE order_id = '$id'");
    $savequery = mysql_query($status_update) or die(mysql_error());

    if(!$savequery)
    {
    die('Error in updating the Order Status');
    }
    else
    {
    echo 'Order Status successfully updated!';
    }
    }
    else
{
    }
?>
<p align="left"><?=$popup_close_text;?></p>
</body>
</html>[/code]
Link to comment
Share on other sites

I'd use a switch() statement

[code]if (isset($_POST['status'])) {

        switch (_POST['status']) {

           case 'filled':
                                # do whatever if filled
                                break;

           case 'received':
                                # do whatever if received
                                break;


           case 'pending':
                                # do whatever if pending
                                break;

           case 'canceled':
                                # do whatever if canceled
                                break;
        }

}[/code]
Link to comment
Share on other sites

  • 2 weeks later...
[!--quoteo(post=360121:date=Mar 30 2006, 02:42 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Mar 30 2006, 02:42 PM) [snapback]360121[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'd use a switch() statement

[code]if (isset($_POST['status'])) {

        switch (_POST['status']) {

           case 'filled':
                                # do whatever if filled
                                break;

           case 'received':
                                # do whatever if received
                                break;
           case 'pending':
                                # do whatever if pending
                                break;

           case 'canceled':
                                # do whatever if canceled
                                break;
        }

}[/code]
[/quote]
I am using that code & can't get it to save to the db with the new information. You can see my code below & see the echo's the names for the different statuses. I can see status display the name that is in the echo, but when I tried adding this form it will display the form & just go blank when I click the [i][b]Fill[/b][/i] button. I am not sure what is causing this.

This is my colde:[code]<?php
if($_POST['save'])
{

if (isset($_POST['status'])) {

        switch ($_POST['status']) {

           case 'Filled': ?>
                  <form name="filled" method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
                Acct:  
                <input name="acct" type="text" id="acct">
                <br>
                Batch:
                <input name="batch" type="text" id="batch">
                <input name="filled" type="submit" class="submit" id="filled" value="Save" />
                </form>
                                
    <?
    if($_POST['filled'])    {
    
    require("../cdb.php");
    $acct = $_POST['acct'];
    $batch = $_POST['batch'];
    $now = date("Y-m-d H:i:s");
    $id = $_REQUEST['id'];

    $status_update = ("UPDATE $orders SET order_status = 'Filled', tu_account = '$acct', tu_batch = '$batch', order_filldate = '$now'  WHERE order_id = '$id'");
    $savequery = mysql_query($status_update) or die(mysql_error());

    if(!$savequery)
    {
    die('Error in updating the Order Status');
    }
    else
    {
    echo 'Order Status successfully updated!';
    }
    }
    
    
    
                                break;

          
           case 'Received':
                                echo 'Received';
                                break;


           case 'Pending':
                                echo 'Pending';
                                break;

           case 'Canceled':
                                echo 'Canceled';
                                break;
        }

}/*
    require("../cdb.php");

    $status = $_POST['status'];
    $now = date("Y-m-d H:i:s");
    $id = $_REQUEST['id'];

    $status_update = ("UPDATE $orders SET order_status = '$status' WHERE order_id = '$id'");
    $savequery = mysql_query($status_update) or die(mysql_error());

    if(!$savequery)
    {
    die('Error in updating the Order Status');
    }
    else
    {
    echo 'Order Status successfully updated!';
    }
    }
    else
{
    */}
?>
[/code]
Link to comment
Share on other sites

You have a "client" and a "server".

Your process is as follows

Client sends "status" to server.

If status == filled a form is sent to the client.

This form then sends "filled", "batch" and "acct" fields back to the server

On the server you only update if "status" == filled. No "status" is sent to the server from this form.
Link to comment
Share on other sites

[!--quoteo(post=364548:date=Apr 13 2006, 03:17 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 13 2006, 03:17 PM) [snapback]364548[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You have a "client" and a "server".

Your process is as follows

Client sends "status" to server.

If status == filled a form is sent to the client.

This form then sends "filled", "batch" and "acct" fields back to the server

On the server you only update if "status" == filled. No "status" is sent to the server from this form.
[/quote]OK...how do I make the form once it is filled out be submited to the same page...[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$_SERVER['PHP_SELF'][!--colorc--][/span][!--/colorc--] ?
Link to comment
Share on other sites

That isn't your problem.

Your problem is that your page isn't prepared for the form contents being returned. It is only processing the original status then sending the form.

One way to do it is add a hidden field named "status" to the the form and give it a value of "filled_form", say.

Then add another case to the switch
[code]
  case "filled_form":
           // process the form and update db
           break;
[/code]
Link to comment
Share on other sites

Thanks....I had to make the action filled of each form to this to get it to work...[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--][i]<?php $_SERVER['PHP_SELF'] ?>[/i][!--colorc--][/span][!--/colorc--] . Thanks for the help!!!
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.