Jump to content


Photo

If / Then question


  • Please log in to reply
7 replies to this topic

#1 lansing

lansing
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationClinton, TN USA

Posted 30 March 2006 - 07:28 PM

I have a drop down menu that updates the status of a record in a MySQL db. I have 4 statuses...Received, Pending, Filled, & Canceled. 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 Filled 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 Filled 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 Cacnelled 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.

<!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>


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,169 posts

Posted 30 March 2006 - 07:42 PM

I'd use a switch() statement

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

}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 lansing

lansing
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationClinton, TN USA

Posted 13 April 2006 - 04:49 PM

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

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

}
[/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 Fill button. I am not sure what is causing this.

This is my colde:
<?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
{
    */}
?>


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,169 posts

Posted 13 April 2006 - 08:17 PM

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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 lansing

lansing
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationClinton, TN USA

Posted 13 April 2006 - 10:05 PM

[!--quoteo(post=364548:date=Apr 13 2006, 03:17 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 13 2006, 03:17 PM) View Post[/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--] ?

#6 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 13 April 2006 - 10:24 PM

leave the "action" parameter out of the <form> tag and it will post back to the same page.

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,169 posts

Posted 13 April 2006 - 10:45 PM

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
  case "filled_form":
           // process the form and update db
           break;

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 lansing

lansing
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationClinton, TN USA

Posted 14 April 2006 - 04:51 PM

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--]<?php $_SERVER['PHP_SELF'] ?>[!--colorc--][/span][!--/colorc--] . Thanks for the help!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users