PDA

View Full Version : If / Then Statement help


lansing
03-06-2006, 12:20 AM
I have a drop down menu that has 3 options..Received, Pending, Filled, & Canceled. I am saving this a db when the user clicks the "save" button. Currently it saves it & does nothing else. I need this to happen.

If the user selects the status of Filled I need to be able to enter a confirmation number & a tracking number & then the save to the db will take place. If the user selects the status of Canceled then enter a reason why it was canceled...kind of like comments of why it was canceled. If they just choose the option Received or Pending then it just saves the status as I currently have it written.

This is my file now...<html>
<head>
<?php require("../vars.php"); ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo "$pop_status" ?></title>
</head>
<body>
<form method="post" 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(isset($_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'");
$sqlquery = mysql_query($status_update) or die(mysql_error());

if(!$sqlquery)
{
echo 'Error in updating the Order Status';
}
else
{
echo 'Order Status successfully updated!';
}
}
?>
<p align="left"><?=$popup_close_text;?></p>
</body>
</html>

degsy
03-06-2006, 02:27 PM
What part are you having problems with?
Where are you getting your confirmation and tracking number from?

Archangel
03-06-2006, 04:16 PM
Not to write all the code for you...your if statement will probably look something like this...

If ($status == 'Filled'){
//Input Filled Form
} elseif ($status == 'Canceled'){
//Input Canceled Form
} else {
//Add everything to DB
}

lansing
03-06-2006, 09:56 PM
What part are you having problems with?
Where are you getting your confirmation and tracking number from?I am not having problems with my current coding, but I would like to be able to enter a reason for why it is Cancelled or if the status is Filled enter the confirmation & tracking numbers. The confirmation number are numbers for the order that generated by us so the user can get the information that he needs/wants. The tracking number would be were the user can go to domain.com/orderstatus?id=555555&pin=1234 & the page display the status & the order comments.


Not to write all the code for you...your if statement will probably look something like this...

If ($status == 'Filled'){
//Input Filled Form
} elseif ($status == 'Canceled'){
//Input Canceled Form
} else {
//Add everything to DB
}Thanks...I was thinking of something along those lines, but just didn't know how. I have now got this much done & it isn't working. I haven't got the coding done that will inset the confirmation number, tracking number, or comments into the db done yet, but will have. If I choose the status Filled & click the save button it just updates the order status & doesn't display the form for adding confirmation number.

<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(isset($_POST['save']))

if($status == 'Filled'){
?>
<form method="post" name="status_filled" action="">
<label for="tu_confirmation">Confirmation # :
<input name="tu_confirmation" type="text" id="tu_confirmation"></label>
<br>
<label for="tu_batch">Tracking # :
<input name="tu_batch" type="text" id="tu_batch">
<br>
<input type="submit" value="Save" name="save2" class="submit" />
</label>
</form>

<?
} elseif ($status == 'Canceled'){
?>
<form method="post" name="status_canceled" action="">
<label for="comments">Coments:
<textarea name="comments" id="comments"></textarea>
</label>
<br>
<input type="submit" value="Save" name="save3" class="submit" />
</label>
</form>

<?
} else {

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'");
$sqlquery = mysql_query($status_update) or die(mysql_error());

if(!$sqlquery)
{
echo 'Error in updating the Order Status';
}
else
{
echo 'Order Status successfully updated!';
}
}
?>
<p align="left"><?=$popup_close_text;?></p>
</body>