Member Avatar for LastMitch

I'm new to this forum but I do read posts as a non-member and I learn a lot from reading other posts from other member. I'm having problem understand how to write the code correctly. I can't seen to figure out the international shipping cost but for domestic it works. What can I write to make the international shipping cost work? I really appreciate if someone explain or show me how to write it so I can learn it and get a better understand how this language work.

Here is the code:

<?php
session_start();
header("Cache-control: private");
require_once ('include/init.php');

if (isset($_POST['ins'])) {
if (!isset($_POST['promo'])) {$promo="no";} else {$promo="yes";}
$sstat = $_POST["stat"];

$sql="INSERT INTO cust(fname, lname, email, addr, city, stat, zip, promo, phone, dt, country) VALUES (".
  "'".mysql_real_escape_string(trim($_POST["fname"]))."', ".
  "'".mysql_real_escape_string(trim($_POST["lname"]))."', ".
  "'".mysql_real_escape_string(trim($_POST["email"]))."', ".
  "'".mysql_real_escape_string(trim($_POST["addr"]))."', ".
  "'".mysql_real_escape_string(trim($_POST["city"]))."', ".
  "'".mysql_real_escape_string(trim($_POST["stat1"]))."', ".
  "'".mysql_real_escape_string(trim($_POST["zip"]))."', ".
  "'".$promo."', ".
  "'".mysql_real_escape_string(trim($_POST["phone"]))."',NOW(),'".trim(mysql_real_escape_string($_POST["country"]))."') ";

$rs= mysql_query($sql);
$uid = mysql_insert_id();
$_SESSION['uid'] = $uid;


$country = trim($_POST["country"]);
$_SESSION['country'] = trim($_POST["country"]);

if (mysql_affected_rows()<0){print "<B>Fatal ERROR: Could not add customer.</B>";exit();}};

if (isset($_POST['place'])) {$sql="SELECT * from cust where id = ".mysql_real_escape_string($_SESSION['uid']);
           $rs= mysql_query($sql) ;
           echo mysql_error();
           $row=mysql_fetch_array($rs);
           $eemail = $row["email"];
           $country = $row["country"];

if ($_POST["express"] == "15"){$express = 15; $expyes = "yes";}else{$express = 0; $expyes = "no";}
          $ordertotal = $_SESSION["tcost"] + $_SESSION["ship"] + $_SESSION["taxx"] + $express ;
          $ordertotal = $_SESSION["tcost"] + $_SESSION["ship"] + $_SESSION["taxx"] + $express ;

          $_SESSION["mthis"] ="" ;
          $_SESSION["mthis"] .=$row["fname"]." ".$row["lname"]."\n" ;
          $_SESSION["mthis"] .=$row["addr"]."\n".$row["city"].", ".$row["stat"].", ".$row["zip"].", "."\n" ;
          $_SESSION["mthis"] .=$row["country"]."\n".$row["email"]."\n".$row["phone"]."\n"."\n"."Order info:"."\n" ;

          $sql="INSERT INTO orders(cust_id, cart_total, taxx, shipping, express, s_first, s_last, s_addr, s_city, s_stat, s_zip, s_email, s_country, dt, s_phone) VALUES (".
          "'".mysql_real_escape_string($row["id"])."', ".
          "'".mysql_real_escape_string($ordertotal)."', ".
          "'".mysql_real_escape_string($_SESSION["taxx"])."', ".
          "'".mysql_real_escape_string($_SESSION["ship"])."', ".
          "'".mysql_real_escape_string($expyes)."', ".
          "'".mysql_real_escape_string($row["fname"])."', ".
          "'".mysql_real_escape_string($row["lname"])."', ".
          "'".mysql_real_escape_string($row["addr"])."', ".
          "'".mysql_real_escape_string($row["city"])."', ".
          "'".mysql_real_escape_string($row["stat"])."', ".
          "'".mysql_real_escape_string($row["zip"])."', ".
          "'".mysql_real_escape_string($row["email"])."', ".
          "'".mysql_real_escape_string($row["country"])."',NOW(),'".mysql_real_escape_string($row["phone"])."') ";

$rs= mysql_query($sql,$o_conn) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
$oid = mysql_insert_id();

$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . mysql_real_escape_string( GetCartId() ) . "' order by items.itemName asc");

if (mysql_num_rows($result)==0){echo mysql_num_rows($result);}
while($row = mysql_fetch_array($result)){
             $_SESSION["mthis"] .=$row["itemName"]." - ".$row["itemStyle"]."\n" ;
             $_SESSION["mthis"] .="Size: ".$row["size"]."\n" ;
             $_SESSION["mthis"] .="Color: ".$row["color"]."\n" ;
             $_SESSION["mthis"] .="Qty: ".$row["qty"]."\n" ;    
             $_SESSION["mthis"] .="Gift wrap: ".ucwords($row["gift_wrap"])."\n" ;
             $_SESSION["mthis"] .="Unit Price: ".$row["price"]."\n"."\n" ;  

             $sql="INSERT INTO order_details(o_id, prod_id, name, size, color, qty, gift_wrap, unitprice, total) VALUES (".
              "'".mysql_real_escape_string($oid)."', ".
              "'".mysql_real_escape_string($row["itemId"])."', ".
              "'".mysql_real_escape_string($row["itemName"])."', ".
              "'".mysql_real_escape_string($row["size"])."', ".
              "'".mysql_real_escape_string($row["color"])."', ".
              "'".mysql_real_escape_string($row["qty"])."', ".
              "'".mysql_real_escape_string($row["gift_wrap"])."', ".
              "'".mysql_real_escape_string($row["price"])."', ".
              "'".mysql_real_escape_string($row["price"]*$row["qty"])."') ";

              $rs= mysql_query($sql, $o_conn) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());}

            $_SESSION["mthis"] .="Shipping = $ ".$_SESSION["ship"]."\n" ;
            $_SESSION["mthis"] .="Express Shippig = $ ".$expyes."\n" ;
            if ($taxx != ""){$_SESSION["mthis"] .="Tax = $ ".$taxx."\n" ;}  
            $_SESSION["mthis"] .="Total = $ ".$ordertotal."\n" ;    
            $_SESSION["mthis"] .="........................................";

            $sendto = "Mitch3@me.com"; 
            $subject = "Website Order";  
            $message = $_SESSION["mthis"];   
            $headers = 'From: order@' . "simplyjiang.com" . "\r\n" .
               'Reply-To: order@' . "simplyjiang.com" . "\r\n" .
               'X-Mailer: PHP/' . phpversion();  
            // send email   
            mail($sendto, $subject, $message, $headers);  

            $_SESSION["oid"] = $oid;
            header("Location: trans/sim.php"); }?>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SimplyJiang - SHOP</title>
<link href="style.css" rel="stylesheet" type="text/css"><style type="text/css">
<!--
.style1 {   font-family: "Times New Roman", Times, serif;
    font-size: 12px;
    color: #333333;
}
.style5 {color: #FFFFFF}
.style8 {font-size: 10px}
-->
        </style>
        <script language="javascript">
        function formatCurrency(num) {
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
        num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
        cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
        num.substring(num.length-(4*i+3));
        return (((sign)?'':'-') + '$' + num + '.' + cents);
        }

        function calcFees(chk,cost){
         if (chk.checked == 1){
  document.getElementById("stotal").innerHTML = formatCurrency(cost + 15);}
  else
  {
  document.getElementById("stotal").innerHTML = formatCurrency(cost);}
        }
        </script>
</head>

    <body>
<table width="800" height="298" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  <tr>
    <td height="298" align="center" valign="top"><p><a href="index_09.html"></a></p>
        <table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="200" height="25" align="center"><h3 align="center" class="style17">CHECKOUT </h3>
                <p align="center" class="style1">Please verify the info <strong></strong> belo<span class="style42">w</span>: <br>
                    <br>
              </p></td>
          </tr>
        </table>
      <div align="center">
          <form action="checkout2.php?" method="post">
<?php
      function GetCartId(){
        // This function will generate an encrypted string and
        // will set it as a cookie using set_cookie. This will
        // also be used as the cookieId field in the cart table

        if(isset($_COOKIE["cartId"])){
            return $_COOKIE["cartId"];
        }
        else{
            // There is no cookie set. We will set the cookie
            // and return the value of the users session ID

            session_start();
            setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
            return session_id();
        }
    }
    $result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . mysql_real_escape_string( GetCartId() ) . "' order by items.itemName asc");?>
            <table width="80%" border="0" align="center" cellpadding="4" cellspacing="0" bgcolor="#CCCCCC">
              <tr>
                <td height="25" bgcolor="#999999" class="style1"><span class="style34 style37 style17 style5 style8">ITEM</span></td>
                <td width="17%" height="25" bgcolor="#999999" class="style1"><span class="style34 style37 style17 style5 style8">COLOR</span></td>
                <td height="25" bgcolor="#999999" class="style1"><span class="style34 style37 style17 style5 style8">QTY</span></td>
                <td height="25" bgcolor="#999999" class="style1" align="center"><span class="style34 style37 style17 style5 style8">GiFT WRAP</span></td>
                <td height="25" bgcolor="#999999" class="style1"><span class="style34 style37 style17 style5 style8">SUBTOTAL</span></td>
              </tr>
              <? if (mysql_num_rows($result)==0){echo mysql_num_rows($result);}

$_SESSION["mthis"] ="";while($row = mysql_fetch_array($result)){

// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["price"]);
if ($sstat == "NY"){$taxx = round($totalCost * .08875,2);}?>
              <tr>
                <td width="57%" height="25" bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"> <?php echo $row["itemName"]; ?> - <font face="verdana"><?php echo $row["size"]; ?></font></font></span></td>
             <td height="25" bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"><?php echo $row["color"]; ?></font></span></td>
             <td width="11%" bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"> <?php echo $row["qty"]; ?> </font></span></td>
             <td width="11%" bgcolor="#FFFFFF" class="style1" align="center"><span class="style32 style8"><font face="verdana"><?php if ($row["gift_wrap"] == 'yes'):?><img src="images/checked.gif" width="15" align="middle" /><?php endif;?></font></span></td>
                <td width="15%" height="25" bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"> $<?php echo number_format($row["price"]*$row["qty"], 2, ".", ","); ?></font></span></td>
              </tr>
              <?php
}

//----------Domestic Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 6.50;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 10.50;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 14.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 18.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 20.00;}
if ($totalCost > 1000){$ship = 25.00;}

//----------International Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 30.00;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 35.00;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 40.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 45.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 50.00;}
if ($totalCost > 1000){$iship = 50.00;} 

//----------store important values in session--------------//
    $_SESSION['tcost'] = $totalCost;
    $_SESSION['ship']  = $ship;
    $_SESSION['taxx']  = $taxx;
//----------store important values in session--------------//?>
              <tr>
                <td colspan="5" bgcolor="#FFFFFF" class="style1"><div align="right">______________________</div></td></tr>
              <tr>
                <td colspan="4" bgcolor="#FFFFFF" class="style1"><div align="right" class="style17 style8"><span class="style39">TAX:</span></div></td>
                <td bgcolor="#FFFFFF" class="style1"><span class="style32 style8"> <font face="verdana"><b>$<?php echo number_format($taxx, 2, ".", ","); ?></b></font></span></td></tr>
              <tr>
                <td colspan="4" bgcolor="#FFFFFF" class="style1"><div align="right" class="style17 style8"><span class="style39">SHIPPING:</span></div></td>
                <td bgcolor="#FFFFFF" class="style1"><span class="style32 style8"> <font face="verdana"><b>$<?php echo number_format($ship, 2, ".", ","); ?></b></font></span></td></tr>
              <tr>
         <td colspan="4" bgcolor="#FFFFFF" class="style1"><div align="right" class="style17 style8"><span class="style39">EXPRESS DELIVERY:* </span></div></td>
         <td bgcolor="#FFFFFF" class="style1"><input name="express" type="checkbox" id="express" onClick="calcFees(express,<?=$totalCost + $ship + $taxx;?>);" value="15"/></td></tr>
              <tr>
                <td colspan="4" bgcolor="#FFFFFF" class="style1"><div align="right" class="style17 style8"><span class="style39">TOTAL:</span></div></td>
                <td bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"><b>
                  <div id="stotal">$<?php echo number_format($totalCost + $ship + $taxx, 2, ".", ","); ?></div>
                </b></font></span></td></tr>
            </table>
              <input name="place" type="hidden" id="place" value="yes" />
              <input name="tcost" type="hidden" id="tcost" value="<? echo $totalCost; ?>" />
              <input name="ship" type="hidden" id="ship" value="<? echo $ship; ?>" />
              <input name="taxx" type="hidden" id="taxx" value="<? echo $taxx; ?>" />
              <input type="submit" name="Submit" value="Place Order" />
            </p>
          </form></div></td></tr></table></body></html>

i should mention ive not changed anything i just put it in code tags

<?php
session_start();
header("Cache-control: private");
require_once ('include/init.php');

if (isset($_POST['ins'])) {
if (!isset($_POST['promo'])) {$promo="no";} else {$promo="yes";}
$sstat = $_POST["stat"];

$sql="INSERT INTO cust(fname, lname, email, addr, city, stat, zip, promo, phone, dt, country) VALUES (".
"'".mysql_real_escape_string(trim($_POST["fname"]))."', ".
"'".mysql_real_escape_string(trim($_POST["lname"]))."', ".
"'".mysql_real_escape_string(trim($_POST["email"]))."', ".
"'".mysql_real_escape_string(trim($_POST["addr"]))."', ".
"'".mysql_real_escape_string(trim($_POST["city"]))."', ".
"'".mysql_real_escape_string(trim($_POST["stat1"]))."', ".
"'".mysql_real_escape_string(trim($_POST["zip"]))."', ".
"'".$promo."', ".
"'".mysql_real_escape_string(trim($_POST["phone"]))."',NOW(),'".trim(mysql_real_escape_string($_POST["country"]))."') ";

$rs= mysql_query($sql);
$uid = mysql_insert_id();
$_SESSION['uid'] = $uid;


$country = trim($_POST["country"]);
$_SESSION['country'] = trim($_POST["country"]);

if (mysql_affected_rows()<0){print "<B>Fatal ERROR: Could not add customer.</B>";exit();}};

if (isset($_POST['place'])) {$sql="SELECT * from cust where id = ".mysql_real_escape_string($_SESSION['uid']);
$rs= mysql_query($sql) ;
echo mysql_error();
$row=mysql_fetch_array($rs);
$eemail = $row["email"];
$country = $row["country"];

if ($_POST["express"] == "15"){$express = 15; $expyes = "yes";}else{$express = 0; $expyes = "no";}
$ordertotal = $_SESSION["tcost"] + $_SESSION["ship"] + $_SESSION["taxx"] + $express ;
$ordertotal = $_SESSION["tcost"] + $_SESSION["ship"] + $_SESSION["taxx"] + $express ;

$_SESSION["mthis"] ="" ;
$_SESSION["mthis"] .=$row["fname"]." ".$row["lname"]."\n" ;
$_SESSION["mthis"] .=$row["addr"]."\n".$row["city"].", ".$row["stat"].", ".$row["zip"].", "."\n" ;
$_SESSION["mthis"] .=$row["country"]."\n".$row["email"]."\n".$row["phone"]."\n"."\n"."Order info:"."\n" ;

$sql="INSERT INTO orders(cust_id, cart_total, taxx, shipping, express, s_first, s_last, s_addr, s_city, s_stat, s_zip, s_email, s_country, dt, s_phone) VALUES (".
"'".mysql_real_escape_string($row["id"])."', ".
"'".mysql_real_escape_string($ordertotal)."', ".
"'".mysql_real_escape_string($_SESSION["taxx"])."', ".
"'".mysql_real_escape_string($_SESSION["ship"])."', ".
"'".mysql_real_escape_string($expyes)."', ".
"'".mysql_real_escape_string($row["fname"])."', ".
"'".mysql_real_escape_string($row["lname"])."', ".
"'".mysql_real_escape_string($row["addr"])."', ".
"'".mysql_real_escape_string($row["city"])."', ".
"'".mysql_real_escape_string($row["stat"])."', ".
"'".mysql_real_escape_string($row["zip"])."', ".
"'".mysql_real_escape_string($row["email"])."', ".
"'".mysql_real_escape_string($row["country"])."',NOW(),'".mysql_real_escape_string($row["phone"])."') ";

$rs= mysql_query($sql,$o_conn) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
$oid = mysql_insert_id();

$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . mysql_real_escape_string( GetCartId() ) . "' order by items.itemName asc");

if (mysql_num_rows($result)==0){echo mysql_num_rows($result);}
while($row = mysql_fetch_array($result)){
$_SESSION["mthis"] .=$row["itemName"]." - ".$row["itemStyle"]."\n" ;
$_SESSION["mthis"] .="Size: ".$row["size"]."\n" ;
$_SESSION["mthis"] .="Color: ".$row["color"]."\n" ;
$_SESSION["mthis"] .="Qty: ".$row["qty"]."\n" ;	
$_SESSION["mthis"] .="Gift wrap: ".ucwords($row["gift_wrap"])."\n" ;
$_SESSION["mthis"] .="Unit Price: ".$row["price"]."\n"."\n" ;	

$sql="INSERT INTO order_details(o_id, prod_id, name, size, color, qty, gift_wrap, unitprice, total) VALUES (".
"'".mysql_real_escape_string($oid)."', ".
"'".mysql_real_escape_string($row["itemId"])."', ".
"'".mysql_real_escape_string($row["itemName"])."', ".
"'".mysql_real_escape_string($row["size"])."', ".
"'".mysql_real_escape_string($row["color"])."', ".
"'".mysql_real_escape_string($row["qty"])."', ".
"'".mysql_real_escape_string($row["gift_wrap"])."', ".
"'".mysql_real_escape_string($row["price"])."', ".
"'".mysql_real_escape_string($row["price"]*$row["qty"])."') ";

$rs= mysql_query($sql, $o_conn) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());}

$_SESSION["mthis"] .="Shipping = $ ".$_SESSION["ship"]."\n" ;
$_SESSION["mthis"] .="Express Shippig = $ ".$expyes."\n" ;
if ($taxx != ""){$_SESSION["mthis"] .="Tax = $ ".$taxx."\n" ;}	
$_SESSION["mthis"] .="Total = $ ".$ordertotal."\n" ;	
$_SESSION["mthis"] .="........................................";

$sendto = "Mitch3@me.com"; 
$subject = "Website Order"; 
$message = $_SESSION["mthis"]; 
$headers = 'From: order@' . "simplyjiang.com" . "\r\n" .
'Reply-To: order@' . "simplyjiang.com" . "\r\n" .
'X-Mailer: PHP/' . phpversion();	
// send email 
mail($sendto, $subject, $message, $headers); 

$_SESSION["oid"] = $oid;
header("Location: trans/sim.php"); }?>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SimplyJiang - SHOP</title>
<link href="style.css" rel="stylesheet" type="text/css"><style type="text/css">
<!--
.style1 {	font-family: "Times New Roman", Times, serif;
font-size: 12px;
color: #333333;
}
.style5 {color: #FFFFFF}
.style8 {font-size: 10px}
-->
</style>
<script language="javascript">
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function calcFees(chk,cost){
if (chk.checked == 1){
document.getElementById("stotal").innerHTML = formatCurrency(cost + 15);}
else
{
document.getElementById("stotal").innerHTML = formatCurrency(cost);}
}
</script>
</head>

<body>
<table width="800" height="298" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr>
<td height="298" align="center" valign="top"><p><a href="index_09.html"></a></p>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="200" height="25" align="center"><h3 align="center" class="style17">CHECKOUT </h3>
<p align="center" class="style1">Please verify the info <strong></strong> belo<span class="style42">w</span>: <br>
<br>
</p></td>
</tr>
</table>
<div align="center">
<form action="checkout2.php?" method="post">
<?php
function GetCartId(){
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table

if(isset($_COOKIE["cartId"])){
return $_COOKIE["cartId"];
}
else{
// There is no cookie set. We will set the cookie
// and return the value of the users session ID

session_start();
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}
$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . mysql_real_escape_string( GetCartId() ) . "' order by items.itemName asc");?>
<table width="80%" border="0" align="center" cellpadding="4" cellspacing="0" bgcolor="#CCCCCC">
<tr>
<td height="25" bgcolor="#999999" class="style1"><span class="style34 style37 style17 style5 style8">ITEM</span></td>
<td width="17%" height="25" bgcolor="#999999" class="style1"><span class="style34 style37 style17 style5 style8">COLOR</span></td>
<td height="25" bgcolor="#999999" class="style1"><span class="style34 style37 style17 style5 style8">QTY</span></td>
<td height="25" bgcolor="#999999" class="style1" align="center"><span class="style34 style37 style17 style5 style8">GiFT WRAP</span></td>
<td height="25" bgcolor="#999999" class="style1"><span class="style34 style37 style17 style5 style8">SUBTOTAL</span></td>
</tr>
<? if (mysql_num_rows($result)==0){echo mysql_num_rows($result);}

$_SESSION["mthis"] ="";while($row = mysql_fetch_array($result)){

// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["price"]);
if ($sstat == "NY"){$taxx = round($totalCost * .08875,2);}?>
<tr>
<td width="57%" height="25" bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"> <?php echo $row["itemName"]; ?> - <font face="verdana"><?php echo $row["size"]; ?></font></font></span></td>
<td height="25" bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"><?php echo $row["color"]; ?></font></span></td>
<td width="11%" bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"> <?php echo $row["qty"]; ?> </font></span></td>
<td width="11%" bgcolor="#FFFFFF" class="style1" align="center"><span class="style32 style8"><font face="verdana"><?php if ($row["gift_wrap"] == 'yes'):?><img src="images/checked.gif" width="15" align="middle" /><?php endif;?></font></span></td>
<td width="15%" height="25" bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"> $<?php echo number_format($row["price"]*$row["qty"], 2, ".", ","); ?></font></span></td>
</tr>
<?php
}

//----------Domestic Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 6.50;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 10.50;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 14.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 18.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 20.00;}
if ($totalCost > 1000){$ship = 25.00;}

//----------International Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 30.00;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 35.00;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 40.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 45.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 50.00;}
if ($totalCost > 1000){$iship = 50.00;} 

//----------store important values in session--------------//
$_SESSION['tcost'] = $totalCost;
$_SESSION['ship'] = $ship;
$_SESSION['taxx'] = $taxx;
//----------store important values in session--------------//?>
<tr>
<td colspan="5" bgcolor="#FFFFFF" class="style1"><div align="right">______________________</div></td></tr>
<tr>
<td colspan="4" bgcolor="#FFFFFF" class="style1"><div align="right" class="style17 style8"><span class="style39">TAX:</span></div></td>
<td bgcolor="#FFFFFF" class="style1"><span class="style32 style8"> <font face="verdana"><b>$<?php echo number_format($taxx, 2, ".", ","); ?></b></font></span></td></tr>
<tr>
<td colspan="4" bgcolor="#FFFFFF" class="style1"><div align="right" class="style17 style8"><span class="style39">SHIPPING:</span></div></td>
<td bgcolor="#FFFFFF" class="style1"><span class="style32 style8"> <font face="verdana"><b>$<?php echo number_format($ship, 2, ".", ","); ?></b></font></span></td></tr>
<tr>
<td colspan="4" bgcolor="#FFFFFF" class="style1"><div align="right" class="style17 style8"><span class="style39">EXPRESS DELIVERY </span></div></td>
<td bgcolor="#FFFFFF" class="style1"><input name="express" type="checkbox" id="express" onClick="calcFees(express,<?=$totalCost + $ship + $taxx;?>);" value="15"/></td></tr>
<tr>
<td colspan="4" bgcolor="#FFFFFF" class="style1"><div align="right" class="style17 style8"><span class="style39">TOTAL:</span></div></td>
<td bgcolor="#FFFFFF" class="style1"><span class="style32 style8"><font face="verdana"><b>
<div id="stotal">$<?php echo number_format($totalCost + $ship + $taxx, 2, ".", ","); ?></div>
</b></font></span></td></tr>
</table>
<input name="place" type="hidden" id="place" value="yes" />
<input name="tcost" type="hidden" id="tcost" value="<? echo $totalCost; ?>" />
<input name="ship" type="hidden" id="ship" value="<? echo $ship; ?>" />
<input name="taxx" type="hidden" id="taxx" value="<? echo $taxx; ?>" />
<input type="submit" name="Submit" value="Place Order" />
</p>
</form></div></td></tr></table></body></html>

You say the problem is with international shipping? i notice this may be off:

//----------Domestic Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 6.50;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 10.50;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 14.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 18.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 20.00;}
if ($totalCost > 1000){$ship = 25.00;}
 
//----------International Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 30.00;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 35.00;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 40.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 45.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 50.00;}
if ($totalCost > 1000){$iship = 50.00;}

Should the international shipping be setting $iship instead of $ship?

That code will only be putting in international shipping because it runs after domestic with the exact same if statement and overwrites the previous value, unless it is over 1000 then it sets $iship instead.

But where is the error and what is not working correctly?

commented: Good Catch! +0
Member Avatar for LastMitch

Hi Biiim,

Thanks for the catch about the 'iship'! I was looking over and over and changing it but that didn't work either.

You mean like this:

//----------Domestic Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 6.50;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 10.50;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 14.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 18.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 20.00;}
if ($totalCost > 1000){$ship = 25.00;}

if else

//----------International Shipping--------------//
 ($totalCost > 0 && $totalCost <= 100){$ship = 30.00;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 35.00;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 40.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 45.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 50.00;}
if ($totalCost > 1000){$ship = 50.00;} 

is that right?
The error is it only calculate Domestic Shipping not International Shipping? when you mean overlapped you mean I have to write another if statement? Do I have to include this part of the script too:

<script type="text/JavaScript">
<!--

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0

  var el=document.getElementById("stat");
  var state = el.options[el.selectedIndex].value;

  var cr=document.getElementById("country");
  var country = cr.options[cr.selectedIndex].value;

  if (state == "none" && country == "United States") {alert("You must select a US state if your shipping country is United States!");}  


  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>

Thanks, I appreciate that you can explain more. So I can have a better understand how it should work. You have a good eye!

The reason i say it overwrites is cause it runs this:

if ($totalCost > 0 && $totalCost <= 100){$ship = 6.50;}

then runs:

if ($totalCost > 0 && $totalCost <= 100){$ship = 30.00;}

so if $totalCost is say 60 it will set $ship to 6.50 then overwrite $ship to 30.00 shortly after

I can't work out how your code distinguishes between international and domestic shipping at all, how does someone select international or domestic shipping on the site?


It should be something like this:

if($shippingtype == 'domestic'){
 //----------Domestic Shipping--------------//
 if ($totalCost > 0 && $totalCost <= 100){$ship = 6.50;}
 if ($totalCost > 100 && $totalCost <= 300){$ship = 10.50;}
 if ($totalCost > 300 && $totalCost <= 500){$ship = 14.00;}
 if ($totalCost > 500 && $totalCost <= 700){$ship = 18.00;}
 if ($totalCost > 700 && $totalCost <= 1000){$ship = 20.00;}
 if ($totalCost > 1000){$ship = 25.00;}
}else{
 //----------International Shipping--------------//
 if ($totalCost > 0 && $totalCost <= 100){$ship = 30.00;}
 if ($totalCost > 100 && $totalCost <= 300){$ship = 35.00;}
 if ($totalCost > 300 && $totalCost <= 500){$ship = 40.00;}
 if ($totalCost > 500 && $totalCost <= 700){$ship = 45.00;}
 if ($totalCost > 700 && $totalCost <= 1000){$ship = 50.00;}
 if ($totalCost > 1000){$ship = 50.00;}
}
commented: Good Explanation! +0
Member Avatar for LastMitch

Hi Biim,

Yes I try "if $shippingtype" and code is country instead of domestic it went to international but it work. The "shippingtype function" that you mention and it work, it did went to international but how do I switch them from domestic to international. Stat means state and Country means Country. I got those country list from UPS. If I write :

if($shippingtype == 'stat'){country == "United States"){$stat="true";}{
//----------Domestic Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 6.50;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 10.50;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 14.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 18.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 20.00;}
if ($totalCost > 1000){$ship = 25.00;}
else{if($shippingtype == 'stat'){country == country){$stat="false";}
return{
//----------International Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 30.00;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 35.00;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 40.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 45.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 50.00;}
if ($totalCost > 1000){$ship = 50.00;}
}

It that right? I know I'm missing a few 'var' in order the function to work correctly. 

Here is the code that you mention distinguishes between international and domestic (It's a form): 

            <h3 align="center" class="style17">CHECKOUT </h3>
                          <p align="center" class="style1">Please fill out the form with your <strong>shipping info</strong> belo<span class="style42">w</span>: </p>
                          <table width="470" border="0" align="center" cellpadding="4" cellspacing="0" bgcolor="#CCCCCC" itempadding="5">
                            <tr bgcolor="#FFFFFF">
                              <td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">First Name *</span></td>
                              <td width="58%" bgcolor="#FFFFFF" class="style1"><input name="fname" type="text" id="fname" size="30" />                              </td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Last Name *</span></td>
                              <td width="58%" bgcolor="#FFFFFF" class="style1"><input name="lname" type="text" id="lname" size="30" />                              </td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Email *</span></td>
                              <td width="58%" bgcolor="#FFFFFF" class="style1"><input name="email" type="text" size="30" />                              </td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping Address *</span></td>
                              <td width="58%" bgcolor="#FFFFFF" class="style1"><span class="style38">
                                <textarea name="addr" cols="35" id="addr"></textarea>
                              </span> </td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping City *</span></td>
                              <td width="58%" bgcolor="#FFFFFF" class="style1"><input name="city" type="text" id="city" size="30" />                              </td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping State (US Only) </span></td>
                              <td width="58%" bgcolor="#FFFFFF" class="style1"><span class="style38"><font face="Verdana, Arial, Helvetica, sans-serif">
                                <select name="stat" id="stat">
                                  <option value="none" selected="selected">none</option>
                                  <option value="AL">Alabama </option>
                                  <option value="AK">Alaska </option>
                                  <option value="AZ">Arizona </option>
                                  <option value="AR">Arkansas </option>
                                  <option value="CA">California </option>
                                  <option value="CO">Colorado </option>
                                  <option value="CT">Connecticut </option>
                                  <option value="DE">Delaware </option>
                                  <option value="DC">District of Columbia </option>
                                  <option value="FL">Florida </option>
                                  <option value="GA">Georgia </option>
                                  <option value="GU">Guam </option>
                                  <option value="HI">Hawaii </option>
                                  <option value="ID">Idaho </option>
                                  <option value="IL">Illinois </option>
                                  <option value="IN">Indiana </option>
                                  <option value="IA">Iowa </option>
                                  <option value="KS">Kansas </option>
                                  <option value="KY">Kentucky </option>
                                  <option value="LA">Louisiana </option>
                                  <option value="ME">Maine </option>
                                  <option value="MD">Maryland </option>
                                  <option value="MA">Massachusetts </option>
                                  <option value="MI">Michigan </option>
                                  <option value="MN">Minnesota </option>
                                  <option value="MS">Mississippi </option>
                                  <option value="MO">Missouri </option>
                                  <option value="MT">Montana </option>
                                  <option value="NE">Nebraska </option>
                                  <option value="NV">Nevada </option>
                                  <option value="NH">New Hampshire </option>
                                  <option value="NJ">New Jersey </option>
                                  <option value="NM">New Mexico </option>
                                  <option value="NY">New York </option>
                                  <option value="NC">North Carolina </option>
                                  <option value="ND">North Dakota </option>
                                  <option value="OH">Ohio </option>
                                  <option value="OK">Oklahoma </option>
                                  <option value="OR">Oregon </option>
                                  <option value="PA">Pennsylvania </option>
                                  <option value="RI">Rhode Island </option>
                                  <option value="SC">South Carolina </option>
                                  <option value="SD">South Dakota </option>
                                  <option value="TN">Tennessee </option>
                                  <option value="TX">Texas </option>
                                  <option value="UT">Utah </option>
                                  <option value="VT">Vermont </option>
                                  <option value="VA">Virginia </option>
                                  <option value="WA">Washington </option>
                                  <option value="WV">West Virginia </option>
                                  <option value="WI">Wisconsin </option>
                                  <option value="WY">Wyoming </option>
                                </select>
                              </font></span></td>
                            </tr>
                               <tr bgcolor="#FFFFFF">
                              <td valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping Country *</span></td>
                              <td bgcolor="#FFFFFF" class="style1"><span class="style38"><font face="Verdana, Arial, Helvetica, sans-serif">
                                <select name="country" id="country">
                                  <option value="none" selected="selected">none</option>
                                                    <option>Afghanistan</option>
                                                    <option>Albania</option>
                                                    <option>Algeria</option>
                                                    <option>American Samoa</option>
                                                    <option>Andorra</option>
                                                    <option>Angola</option>
                                                    <option>Anguilla</option>
                                                    <option>Antarctica</option>
                                                    <option>Antigua</option>
                                                    <option>Argentina</option>
                                                    <option>Armenia</option>
                                                    <option>Aruba</option>
                                                    <option>Ascension Islands</option>
                                                    <option>Australia</option>
                                                    <option>Austria</option>
                                                    <option>Azerbaijan</option>
                                                    <option>Bahamas</option>
                                                    <option>Bahrain</option>
                                                    <option>Bangladesh</option>
                                                    <option>Barbados</option>
                                                    <option>Belarus</option>
                                                    <option>Belgium</option>
                                                    <option>Belize</option>
                                                    <option>Benin</option>
                                                    <option>Bermuda</option>
                                                    <option>Bhutan</option>
                                                    <option>Bolivia</option>
                                                    <option>Bonaire</option>
                                                    <option>Bosnia Herzegovina</option>
                                                    <option>Botswana</option>
                                                    <option>Bouvet Island</option>
                                                    <option>Brazil</option>
                                                    <option>British Indies Chagos</option>
                                                    <option>British Virgin Islands</option>
                                                    <option>Brunei Darussalam</option>
                                                    <option>Bulgaria</option>
                                                    <option>Burkina Faso</option>
                                                    <option>Burundi</option>
                                                    <option>Cambodia</option>
                                                    <option>Cameroon</option>
                                                    <option>Canada</option>
                                                    <option>Cape Verde</option>
                                                    <option>Caroline Islands</option>
                                                    <option>Cayman Islands</option>
                                                    <option>Central African Republic</option>
                                                    <option>Chad</option>
                                                    <option>Chile</option>
                                                    <option>China</option>
                                                    <option>Christmas Island</option>
                                                    <option>Cocos (Keeling) Islands</option>
                                                    <option>Colombia</option>
                                                    <option>Comoros</option>
                                                    <option>Congo</option>
                                                    <option>Cook Islands</option>
                                                    <option>Costa Rica</option>
                                                    <option>Cote D'Ivoire</option>
                                                    <option>Croatia</option>
                                                    <option>Cuba</option>
                                                    <option>Curacao</option>
                                                    <option>Cyprus</option>
                                                    <option>Czech Republic</option>
                                                    <option>Democratic Republic of Congo</option>
                                                    <option>Denmark</option>
                                                    <option>Djibouti</option>
                                                    <option>Dominica</option>
                                                    <option>Dominican Republic</option>
                                                    <option>Ecuador</option>
                                                    <option>Egypt</option>
                                                    <option>El Salvador</option>
                                                    <option>Equatorial Guinea</option>
                                                    <option>Eritrea</option>
                                                    <option>Estonia</option>
                                                    <option>Ethiopia</option>
                                                    <option>Falkland Islands (Malvinas)</option>
                                                    <option>Faroe Islands</option>
                                                    <option>Federated States of Micronesia</option>
                                                    <option>Fiji</option>
                                                    <option>Finland</option>
                                                    <option>France</option>
                                                    <option>French Guiana</option>
                                                    <option>French Polynesia</option>
                                                    <option>French Southern Territories</option>
                                                    <option>Gabon</option>
                                                    <option>Gambia</option>
                                                    <option>Georgia</option>
                                                    <option>Germany</option>
                                                    <option>Ghana</option>
                                                    <option>Gibraltar</option>
                                                    <option>Greece</option>
                                                    <option>Greenland</option>
                                                    <option>Grenada</option>
                                                    <option>Guadeloupe</option>
                                                    <option>Guam</option>
                                                    <option>Guatemala</option>
                                                    <option>Guernsey</option>
                                                    <option>Guinea</option>
                                                    <option>Guinea-Bissau</option>
                                                    <option>Guyana</option>
                                                    <option>Haiti</option>
                                                    <option>Heard Island</option>
                                                    <option>Honduras</option>
                                                    <option>Hong Kong</option>
                                                    <option>Hungary</option>
                                                    <option>Iceland</option>
                                                    <option>India</option>
                                                    <option>Indonesia</option>
                                                    <option>Iran (Islamic Republic of)</option>
                                                    <option>Iraq</option>
                                                    <option>Ireland (Republic of)</option>
                                                    <option>Israel</option>
                                                    <option>Italy</option>
                                                    <option>Ivory Coast</option>
                                                    <option>Jamaica</option>
                                                    <option>Japan</option>
                                                    <option>Jersey</option>
                                                    <option>Jordan</option>
                                                    <option>Kazakhstan</option>
                                                    <option>Kenya</option>
                                                    <option>Kiribati</option>
                                                    <option>Kuwait</option>
                                                    <option>Kyrgyzstan</option>
                                                    <option>Lao People's Democratic Republic</option>
                                                    <option>Latvia</option>
                                                    <option>Lebanon</option>
                                                    <option>Lesotho</option>
                                                    <option>Liberia</option>
                                                    <option>Libya</option>
                                                    <option>Liechtenstein</option>
                                                    <option>Lithuania</option>
                                                    <option>Luxembourg</option>
                                                    <option>Macau</option>
                                                    <option>Macedonia (FYROM)</option>
                                                    <option>Madagascar</option>
                                                    <option>Malawi</option>
                                                    <option>Malaysia</option>
                                                    <option>Maldives</option>
                                                    <option>Mali</option>
                                                    <option>Malta</option>
                                                    <option>Marshall Islands</option>
                                                    <option>Martinique</option>
                                                    <option>Mauritania</option>
                                                    <option>Mauritius</option>
                                                    <option>Mayotte</option>
                                                    <option>McDonald Islands</option>
                                                    <option>Mexico</option>
                                                    <option>Midway</option>
                                                    <option>Moldova</option>
                                                    <option>Monaco</option>
                                                    <option>Mongolia</option>
                                                    <option>Montenegro</option>
                                                    <option>Montserrat</option>
                                                    <option>Morocco</option>
                                                    <option>Mozambique</option>
                                                    <option>Myanmar</option>
                                                    <option>Namibia</option>
                                                    <option>Nauru</option>
                                                    <option>Nepal</option>
                                                    <option>Netherlands</option>
                                                    <option>Netherlands Antilles</option>
                                                    <option>New Caledonia</option>
                                                    <option>New Zealand</option>
                                                    <option>Nicaragua</option>
                                                    <option>Niger</option>
                                                    <option>Nigeria</option>
                                                    <option>Niue</option>
                                                    <option>Norfolk Island</option>
                                                    <option>North Korea</option>
                                                    <option>Northern Mariana Islands</option>
                                                    <option>Norway</option>
                                                    <option>Oman</option>
                                                    <option>Pakistan</option>
                                                    <option>Palau</option>
                                                    <option>Panama</option>
                                                    <option>Papua New Guinea</option>
                                                    <option>Paraguay</option>
                                                    <option>Peru</option>
                                                    <option>Philippines</option>
                                                    <option>Pitcairn</option>
                                                    <option>Poland</option>
                                                    <option>Portugal</option>
                                                    <option>Puerto Rico</option>
                                                    <option>Qatar</option>
                                                    <option>Reunion</option>
                                                    <option>Romania</option>
                                                    <option>Russia</option>
                                                    <option>Rwanda</option>
                                                    <option>Saint Helena</option>
                                                    <option>Saint Pierre and Miquelon</option>
                                                    <option>Samoa</option>
                                                    <option>San Marino</option>
                                                    <option>Sao Tome and Principe</option>
                                                    <option>Saudi Arabia</option>
                                                    <option>Senegal</option>
                                                    <option>Serbia</option>
                                                    <option>Seychelles</option>
                                                    <option>Sierra Leone</option>
                                                    <option>Singapore</option>
                                                    <option>Slovakia</option>
                                                    <option>Slovenia</option>
                                                    <option>Solomon Islands</option>
                                                    <option>Somalia</option>
                                                    <option>South Africa</option>
                                                    <option>South Korea</option>
                                                    <option>Spain</option>
                                                    <option>Sri Lanka</option>
                                                    <option>St. Barthelemy</option>
                                                    <option>St. Croix</option>
                                                    <option>St. Eustatius</option>
                                                    <option>St. John</option>
                                                    <option>St. Kitts and Nevis</option>
                                                    <option>St. Lucia</option>
                                                    <option>St. Maarten</option>
                                                    <option>St. Thomas</option>
                                                    <option>St. Vincent and the Grenadines</option>
                                                    <option>Sudan</option>
                                                    <option>Suriname</option>
                                                    <option>Swaziland</option>
                                                    <option>Sweden</option>
                                                    <option>Switzerland</option>
                                                    <option>Syria</option>
                                                    <option>Taiwan</option>
                                                    <option>Tajikistan</option>
                                                    <option>Tanzania</option>
                                                    <option>Thailand</option>
                                                    <option>Timor Leste</option>
                                                    <option>Togo</option>
                                                    <option>Tokelau</option>
                                                    <option>Tonga</option>
                                                    <option>Tortola</option>
                                                    <option>Trinidad and Tobago</option>
                                                    <option>Tunisia</option>
                                                    <option>Turkey</option>
                                                    <option>Turkmenistan</option>
                                                    <option>Turks and Caicos</option>
                                                    <option>Tuvalu</option>
                                                    <option>Uganda</option>
                                                    <option>Ukraine</option>
                                                    <option>Union Island</option>
                                                    <option>United Arab Emirates</option>
                                                    <option>United Kingdom</option>
                                                    <option>United States</option>
                                                    <option>Uruguay</option>
                                                    <option>US Virgin Islands</option>
                                                    <option>Uzbekistan</option>
                                                    <option>Vanuatu</option>
                                                    <option>Vatican City</option>
                                                    <option>Venezuela</option>
                                                    <option>Vietnam</option>
                                                    <option>Virgin Gorda</option>
                                                    <option>Wake Island</option>
                                                    <option>Wallis and Futuna</option>
                                                    <option>Western Sahara</option>
                                                    <option>Yemen</option>
                                                    <option>Zambia</option>
                                                    <option>Zimbabwe</option>
                                </select>
                            </font></span></td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping Zip *</span></td>
                              <td width="58%" bgcolor="#FFFFFF" class="style1"><input name="zip" type="text" id="zip" size="10" />                              </td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Phone *<br />
                                (please include area code) </span></td>
                              <td width="58%" bgcolor="#FFFFFF" class="style1"><input name="phone" type="text" />                              </td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Mailing List</span></td>
                              <td bgcolor="#FFFFFF" class="style1"><input name="promo" type="checkbox" id="promo" value="1" />
                                  <span class="style15">(Please check this box if you would like to be part of our future mailing list and receive promotional items and discounts on products) </span></td>
                            </tr>
                            <tr align="center" bgcolor="#FFFFFF">
                              <td colspan="2" bgcolor="#FFFFFF"><div align="left" class="style38"><b>
                                  <input name="Submit" type="submit" id="Submit" onclick="MM_validateForm('fname','','R','lname','','R','city','','R','zip','','R','phone','','R','addr','','R');return document.MM_returnValue" value="Next" />
                                  <input name="ins" type="hidden" id="ins" value="customer" />
                                  <input name="country" type="hidden" id="country" value="United States">
                              </b>
                              </div></td>
                            </tr>
                          </table>
                          <br>

                        </form>
                        </td>
                      </tr>
                  </table>                  </td>
                  <td width="1"><p align="center"><br>
                  </p>                  </td>
                </tr>
    </table>

Am I missing something? Did I type it wrong again?

Hi Biim,

Yes I try "if $shippingtype" and code is country instead of domestic it went to international but it work. The "shippingtype function" that you mention and it work, it did went to international but how do I switch them from domestic to international. Stat means state and Country means Country. I got those country list from UPS. If I write :


if($shippingtype == 'stat'){country == "United States"){$stat="true";}{
//----------Domestic Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 6.50;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 10.50;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 14.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 18.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 20.00;}
if ($totalCost > 1000){$ship = 25.00;}
else{if($shippingtype == 'stat'){country == country){$stat="false";}
return{
//----------International Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 30.00;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 35.00;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 40.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 45.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 50.00;}
if ($totalCost > 1000){$ship = 50.00;}
}

It that right? I know I'm missing a few 'var' in order the function to work correctly.

Here is the code that you mention distinguishes between international and domestic (It's a form):

<h3 align="center" class="style17">CHECKOUT </h3>
<p align="center" class="style1">Please fill out the form with your <strong>shipping info</strong> belo<span class="style42">w</span>: </p>
<table width="470" border="0" align="center" cellpadding="4" cellspacing="0" bgcolor="#CCCCCC" itempadding="5">
<tr bgcolor="#FFFFFF">
<td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">First Name *</span></td>
<td width="58%" bgcolor="#FFFFFF" class="style1"><input name="fname" type="text" id="fname" size="30" /> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Last Name *</span></td>
<td width="58%" bgcolor="#FFFFFF" class="style1"><input name="lname" type="text" id="lname" size="30" /> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Email *</span></td>
<td width="58%" bgcolor="#FFFFFF" class="style1"><input name="email" type="text" size="30" /> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping Address *</span></td>
<td width="58%" bgcolor="#FFFFFF" class="style1"><span class="style38">
<textarea name="addr" cols="35" id="addr"></textarea>
</span> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping City *</span></td>
<td width="58%" bgcolor="#FFFFFF" class="style1"><input name="city" type="text" id="city" size="30" /> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping State (US Only) </span></td>
<td width="58%" bgcolor="#FFFFFF" class="style1"><span class="style38"><font face="Verdana, Arial, Helvetica, sans-serif">
<select name="stat" id="stat">
<option value="none" selected="selected">none</option>
<option value="AL">Alabama </option>
<option value="AK">Alaska </option>
<option value="AZ">Arizona </option>
<option value="AR">Arkansas </option>
<option value="CA">California </option>
<option value="CO">Colorado </option>
<option value="CT">Connecticut </option>
<option value="DE">Delaware </option>
<option value="DC">District of Columbia </option>
<option value="FL">Florida </option>
<option value="GA">Georgia </option>
<option value="GU">Guam </option>
<option value="HI">Hawaii </option>
<option value="ID">Idaho </option>
<option value="IL">Illinois </option>
<option value="IN">Indiana </option>
<option value="IA">Iowa </option>
<option value="KS">Kansas </option>
<option value="KY">Kentucky </option>
<option value="LA">Louisiana </option>
<option value="ME">Maine </option>
<option value="MD">Maryland </option>
<option value="MA">Massachusetts </option>
<option value="MI">Michigan </option>
<option value="MN">Minnesota </option>
<option value="MS">Mississippi </option>
<option value="MO">Missouri </option>
<option value="MT">Montana </option>
<option value="NE">Nebraska </option>
<option value="NV">Nevada </option>
<option value="NH">New Hampshire </option>
<option value="NJ">New Jersey </option>
<option value="NM">New Mexico </option>
<option value="NY">New York </option>
<option value="NC">North Carolina </option>
<option value="ND">North Dakota </option>
<option value="OH">Ohio </option>
<option value="OK">Oklahoma </option>
<option value="OR">Oregon </option>
<option value="PA">Pennsylvania </option>
<option value="RI">Rhode Island </option>
<option value="SC">South Carolina </option>
<option value="SD">South Dakota </option>
<option value="TN">Tennessee </option>
<option value="TX">Texas </option>
<option value="UT">Utah </option>
<option value="VT">Vermont </option>
<option value="VA">Virginia </option>
<option value="WA">Washington </option>
<option value="WV">West Virginia </option>
<option value="WI">Wisconsin </option>
<option value="WY">Wyoming </option>
</select>
</font></span></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping Country *</span></td>
<td bgcolor="#FFFFFF" class="style1"><span class="style38"><font face="Verdana, Arial, Helvetica, sans-serif">
<select name="country" id="country">
<option value="none" selected="selected">none</option>
<option>Afghanistan</option>
<option>Albania</option>
<option>Algeria</option>
<option>American Samoa</option>
<option>Andorra</option>
<option>Angola</option>
<option>Anguilla</option>
<option>Antarctica</option>
<option>Antigua</option>
<option>Argentina</option>
<option>Armenia</option>
<option>Aruba</option>
<option>Ascension Islands</option>
<option>Australia</option>
<option>Austria</option>
<option>Azerbaijan</option>
<option>Bahamas</option>
<option>Bahrain</option>
<option>Bangladesh</option>
<option>Barbados</option>
<option>Belarus</option>
<option>Belgium</option>
<option>Belize</option>
<option>Benin</option>
<option>Bermuda</option>
<option>Bhutan</option>
<option>Bolivia</option>
<option>Bonaire</option>
<option>Bosnia Herzegovina</option>
<option>Botswana</option>
<option>Bouvet Island</option>
<option>Brazil</option>
<option>British Indies Chagos</option>
<option>British Virgin Islands</option>
<option>Brunei Darussalam</option>
<option>Bulgaria</option>
<option>Burkina Faso</option>
<option>Burundi</option>
<option>Cambodia</option>
<option>Cameroon</option>
<option>Canada</option>
<option>Cape Verde</option>
<option>Caroline Islands</option>
<option>Cayman Islands</option>
<option>Central African Republic</option>
<option>Chad</option>
<option>Chile</option>
<option>China</option>
<option>Christmas Island</option>
<option>Cocos (Keeling) Islands</option>
<option>Colombia</option>
<option>Comoros</option>
<option>Congo</option>
<option>Cook Islands</option>
<option>Costa Rica</option>
<option>Cote D'Ivoire</option>
<option>Croatia</option>
<option>Cuba</option>
<option>Curacao</option>
<option>Cyprus</option>
<option>Czech Republic</option>
<option>Democratic Republic of Congo</option>
<option>Denmark</option>
<option>Djibouti</option>
<option>Dominica</option>
<option>Dominican Republic</option>
<option>Ecuador</option>
<option>Egypt</option>
<option>El Salvador</option>
<option>Equatorial Guinea</option>
<option>Eritrea</option>
<option>Estonia</option>
<option>Ethiopia</option>
<option>Falkland Islands (Malvinas)</option>
<option>Faroe Islands</option>
<option>Federated States of Micronesia</option>
<option>Fiji</option>
<option>Finland</option>
<option>France</option>
<option>French Guiana</option>
<option>French Polynesia</option>
<option>French Southern Territories</option>
<option>Gabon</option>
<option>Gambia</option>
<option>Georgia</option>
<option>Germany</option>
<option>Ghana</option>
<option>Gibraltar</option>
<option>Greece</option>
<option>Greenland</option>
<option>Grenada</option>
<option>Guadeloupe</option>
<option>Guam</option>
<option>Guatemala</option>
<option>Guernsey</option>
<option>Guinea</option>
<option>Guinea-Bissau</option>
<option>Guyana</option>
<option>Haiti</option>
<option>Heard Island</option>
<option>Honduras</option>
<option>Hong Kong</option>
<option>Hungary</option>
<option>Iceland</option>
<option>India</option>
<option>Indonesia</option>
<option>Iran (Islamic Republic of)</option>
<option>Iraq</option>
<option>Ireland (Republic of)</option>
<option>Israel</option>
<option>Italy</option>
<option>Ivory Coast</option>
<option>Jamaica</option>
<option>Japan</option>
<option>Jersey</option>
<option>Jordan</option>
<option>Kazakhstan</option>
<option>Kenya</option>
<option>Kiribati</option>
<option>Kuwait</option>
<option>Kyrgyzstan</option>
<option>Lao People's Democratic Republic</option>
<option>Latvia</option>
<option>Lebanon</option>
<option>Lesotho</option>
<option>Liberia</option>
<option>Libya</option>
<option>Liechtenstein</option>
<option>Lithuania</option>
<option>Luxembourg</option>
<option>Macau</option>
<option>Macedonia (FYROM)</option>
<option>Madagascar</option>
<option>Malawi</option>
<option>Malaysia</option>
<option>Maldives</option>
<option>Mali</option>
<option>Malta</option>
<option>Marshall Islands</option>
<option>Martinique</option>
<option>Mauritania</option>
<option>Mauritius</option>
<option>Mayotte</option>
<option>McDonald Islands</option>
<option>Mexico</option>
<option>Midway</option>
<option>Moldova</option>
<option>Monaco</option>
<option>Mongolia</option>
<option>Montenegro</option>
<option>Montserrat</option>
<option>Morocco</option>
<option>Mozambique</option>
<option>Myanmar</option>
<option>Namibia</option>
<option>Nauru</option>
<option>Nepal</option>
<option>Netherlands</option>
<option>Netherlands Antilles</option>
<option>New Caledonia</option>
<option>New Zealand</option>
<option>Nicaragua</option>
<option>Niger</option>
<option>Nigeria</option>
<option>Niue</option>
<option>Norfolk Island</option>
<option>North Korea</option>
<option>Northern Mariana Islands</option>
<option>Norway</option>
<option>Oman</option>
<option>Pakistan</option>
<option>Palau</option>
<option>Panama</option>
<option>Papua New Guinea</option>
<option>Paraguay</option>
<option>Peru</option>
<option>Philippines</option>
<option>Pitcairn</option>
<option>Poland</option>
<option>Portugal</option>
<option>Puerto Rico</option>
<option>Qatar</option>
<option>Reunion</option>
<option>Romania</option>
<option>Russia</option>
<option>Rwanda</option>
<option>Saint Helena</option>
<option>Saint Pierre and Miquelon</option>
<option>Samoa</option>
<option>San Marino</option>
<option>Sao Tome and Principe</option>
<option>Saudi Arabia</option>
<option>Senegal</option>
<option>Serbia</option>
<option>Seychelles</option>
<option>Sierra Leone</option>
<option>Singapore</option>
<option>Slovakia</option>
<option>Slovenia</option>
<option>Solomon Islands</option>
<option>Somalia</option>
<option>South Africa</option>
<option>South Korea</option>
<option>Spain</option>
<option>Sri Lanka</option>
<option>St. Barthelemy</option>
<option>St. Croix</option>
<option>St. Eustatius</option>
<option>St. John</option>
<option>St. Kitts and Nevis</option>
<option>St. Lucia</option>
<option>St. Maarten</option>
<option>St. Thomas</option>
<option>St. Vincent and the Grenadines</option>
<option>Sudan</option>
<option>Suriname</option>
<option>Swaziland</option>
<option>Sweden</option>
<option>Switzerland</option>
<option>Syria</option>
<option>Taiwan</option>
<option>Tajikistan</option>
<option>Tanzania</option>
<option>Thailand</option>
<option>Timor Leste</option>
<option>Togo</option>
<option>Tokelau</option>
<option>Tonga</option>
<option>Tortola</option>
<option>Trinidad and Tobago</option>
<option>Tunisia</option>
<option>Turkey</option>
<option>Turkmenistan</option>
<option>Turks and Caicos</option>
<option>Tuvalu</option>
<option>Uganda</option>
<option>Ukraine</option>
<option>Union Island</option>
<option>United Arab Emirates</option>
<option>United Kingdom</option>
<option>United States</option>
<option>Uruguay</option>
<option>US Virgin Islands</option>
<option>Uzbekistan</option>
<option>Vanuatu</option>
<option>Vatican City</option>
<option>Venezuela</option>
<option>Vietnam</option>
<option>Virgin Gorda</option>
<option>Wake Island</option>
<option>Wallis and Futuna</option>
<option>Western Sahara</option>
<option>Yemen</option>
<option>Zambia</option>
<option>Zimbabwe</option>
</select>
</font></span></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Shipping Zip *</span></td>
<td width="58%" bgcolor="#FFFFFF" class="style1"><input name="zip" type="text" id="zip" size="10" /> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="42%" valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Phone *<br />
(please include area code) </span></td>
<td width="58%" bgcolor="#FFFFFF" class="style1"><input name="phone" type="text" /> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign="top" bgcolor="#FFFFFF" class="style1"><span class="style15">Mailing List</span></td>
<td bgcolor="#FFFFFF" class="style1"><input name="promo" type="checkbox" id="promo" value="1" />
<span class="style15">(Please check this box if you would like to be part of our future mailing list and receive promotional items and discounts on products) </span></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td colspan="2" bgcolor="#FFFFFF"><div align="left" class="style38"><b>
<input name="Submit" type="submit" id="Submit" onclick="MM_validateForm('fname','','R','lname','','R','city','','R','zip','','R','phone','','R','addr','','R');return document.MM_returnValue" value="Next" />
<input name="ins" type="hidden" id="ins" value="customer" />
<input name="country" type="hidden" id="country" value="United States">
</b>
</div></td>
</tr>
</table>
<br>

</form>
</td>
</tr>
</table> </td>
<td width="1"><p align="center"><br>
</p> </td>
</tr>
</table>

Am I missing something? Did I type it wrong again?

Sorry for having to wait 2 days.

Here's how I would do it, if you only have domestic or international you only need the domestic array, I just put in the others in case you would use different costs if you knew how to.

//set the different postal areas you will charge different prices for
$domestic = array('United States','Canada');//canada is pretty close?
$europe = array('Italy','United Kingdom','Sweden','Slovakia','France','Germany');
$southamerica = array('Brazil','Chile');
$eastasia = array('Japan','India','China');

if(in_array($_POST['country'],$domestic)){//country in $domestic array, domestic shipping costs
//----------Domestic Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 6.50;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 10.50;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 14.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 18.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 20.00;}
if ($totalCost > 1000){$ship = 25.00;}
}elseif(in_array($_POST['country'],$europe)){//country in $europe array, european shipping costs
//----------International Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 20.00;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 28.00;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 32.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 35.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 40.00;}
if ($totalCost > 1000){$ship = 40.00;}
}else{//country not in any array, standard international shipping
//----------International Shipping--------------//
if ($totalCost > 0 && $totalCost <= 100){$ship = 30.00;}
if ($totalCost > 100 && $totalCost <= 300){$ship = 35.00;}
if ($totalCost > 300 && $totalCost <= 500){$ship = 40.00;}
if ($totalCost > 500 && $totalCost <= 700){$ship = 45.00;}
if ($totalCost > 700 && $totalCost <= 1000){$ship = 50.00;}
if ($totalCost > 1000){$ship = 50.00;}
}
?>
commented: Good Example & Explanation! +0
Member Avatar for LastMitch

Hi Biiim,

I solve my problem! The issue was that I forgot to establish a 'var' function in the preivous page in order for that script that you wrote above to work properly. I think I just overlook it. But now, it works fine. I just want to 'Thank You' for taking your time to explained how the function works and also how the script works too. I appreaciated your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.