FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Help fix this code. Pays alot!

 


warallthetm
I wrote a code for one of my clients that calulates the distance from thier house to the clients house. If its over 35 miles away it charges 50 cents a mile. I need someone to make it so that if the address is invalid or mapquest cant find it, that it echos an error. Here is the script::

Code:

<?php
// (c)2007 Aaron Velazquez "warallthetm"
//This script may not be used without express permission of Aaron Velazquez "warallthetm"
//Calculator class that calculates driving distance via mapquest
$address = $_GET["address"];
$zip = $_GET["zip"];
$url = "http://www.mapquest.com/directions/main.adp?go=1&do=nw&1a=28+pewter+circle&1c=chester&1s=ny&1z=10918&2pn=&2a=$address&2c=&2s=&2z=$zip&r=f";

        $filepointer = fopen($url,"r");

  if($filepointer){

  while(!feof($filepointer)){

              $buffer = fgets($filepointer, 4096);

                $file .= $buffer;

            }

            fclose($filepointer);

         } else {

              die("Could not Connect to Database. Please Try again");   

        }

    ?>

    <?php
// /<span class="txt_body"><br>([^`]*?)<\/span>/
          preg_match("/<p><b>Total Est. Distance:<\/b>&nbsp;<span>([^`]*?) miles<\/span>/",$file,$match);

         $result = $match[1];

           

// now do the calculator
$max_before_pay = 35.00;
$location = $result;

if ($max_before_pay > $location) {

print("<br>You live $result miles away<br> <font color=\"green\">Your Shipping is free!</font>");

}
else if($max_before_pay < $location) {
$miles = $location - 35;
$cost=$miles * .50;
print("<br>You live $result miles away<br>Your shipping will cost:: <br><font color=\"green\">$ $cost</font>");

}
?>
Boffel
Is this c++ or java? You should try find another forum for this, its many out there that will help you with this for free. Just so you know lol Laughing
Hobbit
The code begins with
<?php

so its obviously php. Wink
mathiaus
Code:
<?php
// (c)2007 Aaron Velazquez "warallthetm"
//This script may not be used without express permission of Aaron Velazquez "warallthetm"
//Calculator class that calculates driving distance via mapquest
$address = $_GET['address'];
$zip = $_GET['zip'];
$url = 'http://www.mapquest.com/directions/main.adp?go=1&do=nw&1a=28+pewter+circle&1c=chester&1s=ny&1z=10918&2pn=&2a='.$address.'&2c=&2s=&2z='.$zip.'&r=f';

$filepointer = fopen($url,"r");

if($filepointer){

   while(!feof($filepointer)){
       $buffer = fgets($filepointer, 4096);
       $file .= $buffer;
   }
   fclose($filepointer);

   preg_match("/<p><b>Total Est. Distance:<\/b>&nbsp;<span>([^`]*?) miles<\/span>/",$file,$match);
   
   if(empty($match)) {
      die('Sorry, your address could not be found. Please Try again');
   } else {
      $result = $match[1];
   }

   // now do the calculator
   $max_before_pay = 35.00;
   $location = $result;

   if ($max_before_pay >= $location) {
      print('<br />You live '.$result.' miles away. <br /><span style="color:green">Your Shipping is free!</style>');
      
   } elseif($max_before_pay < $location) {
      $miles = $location - 35;
      $cost = $miles * .50;
      print('<br />You live '.$result.' miles away <br />Your shipping will cost: <br /><span style="color:green">'.$cost.'</style>');
   }

   
} else {
     die('Could not Connect to Database. Please Try again');   
}

?>
Reply to topic    Frihost Forum Index -> Miscellaneous -> Marketplace

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.