Jump to content

Using the "||" and "&&" operators


jetlife76

Recommended Posts

Ok here's my issue, im trying to create a program that will calculate the total cost of an item, tax, shipping and shipping date, so far i've ran into a problem setting up my "If" statement with the perameters needed to calculate the shipping cost, Here's the code i have  so far:

 

<?php

$Cost = $_POST['fielda'];

$Tax = ($Cost * .06);

$Sub = ($Cost + $Tax);

$Ship =

$Total = ($Cost + $Tax + $Ship);

 

if ( $Sub <= 25.99 ){

print "$Ship: 3.00<br>"; }

elseif ($Sub >= 26.00 || <= 50.99 ){

print "$Ship: 4.00<br>";}

elseif ($Sub >= 51.00 || <= 75.00) {

print "$Ship: 5.00<br>";}

elseif ($Sub > 75.00) {

print "Ship: 6.00<br>";}

else {

print ("Cost : $Cost<br> Tax: $Tax<br> Shippingtotal is $$Total");}

?>

 

Here's the error i keep getting:

 

Parse error: syntax error, unexpected T_IS_SMALLER_OR_EQUAL in C:\wamp\ on line 16

any help i can get will be greatly appreciated, I also need to know how to do the shipping date (15 days) as well if you can help with that as well

Link to comment
https://forums.phpfreaks.com/topic/248844-using-the-and-operators/
Share on other sites

try this:

 

<?php
$Cost = $_POST['fielda'];
$Tax = ($Cost * .06);
$Sub = ($Cost + $Tax);
$Ship = 0;

if ( $Sub <= 25.99 ){
   $Ship= 3.00; }
elseif ($Sub >= 26.00 || $Sub <= 50.99 ){
   $Ship= 4.00; }
elseif ($Sub >= 51.00 || $Sub <= 75.00) {
   $Ship: 5.00; }
elseif ($Sub > 75.00) {
   $Ship= 6.00; }

$Total = ($Cost + $Tax + $Ship);
print ("Cost : $Cost<br> Tax: $Tax<br> Ship: $Ship<br> Shipping total is $Total");}
?>

its a logic error... take out the elseif's and use && instead of ||. that should fix it.

<?php
$Cost = $_POST['fielda'];
$Tax = ($Cost * .06);
$Sub = ($Cost + $Tax);
if ( $Sub <= 25.99 ) $Ship= 3.00; 
if ($Sub >= 26.00 && $Sub <= 50.99 ) $Ship= 4.00;
if ($Sub >= 51.00 && $Sub <= 75.00) $Ship: 5.00; 
if ($Sub > 75.00) $Ship= 6.00; 

$Total = ($Cost + $Tax + $Ship);
print ("Cost : $Cost<br> Tax: $Tax<br> Ship: $Ship<br> Shipping total is $Total");
?>

Or, you could build it in reverse.

<?php
$Cost = $_POST['fielda'];
$Tax = ($Cost * .06);
$Sub = ($Cost + $Tax);
if ( $Sub > 75.00 ) $Ship= 6.00; 
elseif ($Sub > 51.00 ) $Ship= 5.00;
elseif ($Sub > 26.00) $Ship: 4.00; 
else  $Ship= 3.00; 

$Total = ($Cost + $Tax + $Ship);
print ("Cost : $Cost<br> Tax: $Tax<br> Ship: $Ship<br> Shipping total is $Total");
?>

ok cool thanks, one more thing then i'll be good to go from here, im trying to also show the shipping date which is 15 days after the order date would i use the timestamp, "$ShipDate = mktime(0,0,0,date("m"),date("d")+1,date("Y"));"

but im only getting a list of numbers i want it to show the month spelled out, the day, year

How do i set the current date as well, last question and i swear im done

Thanks in advance

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.