I have a form that calculates a total number using Javascript. The code for the Javascript was taken from here.
Once the user submits the form, he is taken to the next page. On the next page, the PHP displays the form total again (this part works), and then, it is supposed to display a different output based on the range of numbers the total is between.
For instance, if the total is between 1 – 250 (say, 100), then X should be displayed. If the total is between 251 – 500 (say, 350), then Y should be displayed. At the moment, it keeps displaying the same output no matter what the total is.
You can see the form in action here.
Here is the PHP code that I’m using (this will be on the page the user is re-directed to:
<?php session_start();
if ($_POST && !empty($_POST['TOTAL'])) {
$_SESSION['TOTAL'] = $_POST['TOTAL'];
} ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<?php
if (isset($_SESSION['TOTAL'])) {
echo 'Your total volume is ' . round($_SESSION['TOTAL']) . ' Cubic Feet. The total price for your shipment is:';
} else {
echo 'You did not fill out any details. Please go back.';
}
if (isset($_SESSION['TOTAL']) > 0 && isset($_SESSION['TOTAL']) <= 250) { echo ' $1,000';}
if (isset($_SESSION['TOTAL']) > 250 && isset($_SESSION['TOTAL']) <= 500) { echo ' $2,000';}
if (isset($_SESSION['TOTAL']) > 501 && isset($_SESSION['TOTAL']) <= 1000) { echo ' $4,000';}
else { echo 'Sorry, we do not have a price for that.';}
?>
</body>
Thank you in advance.
Do not use
issetfor your equations (it returnstrueif the value is set andtrueis always>0and<250). So instead ofsay
Also use
elseifto ensure, only one block is executed: