Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Please help I can't find what is wrong

Hello,

I have create a website for a car rental company in which the client can select from a form the pick up date-time and drop off date-time in order to send an enquiry to the company asking for a specific car. The pick up date and drop off date is selected from a pop up calendar that displays the values to the two texfields pickupdate and dropoffdate. The pickup time and drop off time are selected from a list menu.

The whole idea is after the user select the dates and times for renting a car, a list of all the cars appears together with the price for every car depending the season he select.

There are three seasons:
Low:      01/04 -15/06
              01/10 – 31/10
Middle: 16/06 – 15/07
              01/09- 30/09
High:     16/07 – 31/08

The total price of a car is been calculated taking into account the discount for the number of dates, the insurance, the season and which category is the car. I have create a function in php that is doing the calculation. The code is the following:

function calculate($x1,$z2,$y3,$category) {

$discount_low[0]=0;
$discount_low[1]=0.30;
$discount_low[2]=0.40;

$discount_middle[0]=0;
$discount_middle[1]=0.25;
$discount_middle[3]=0.35;

$discount_high[0]=0;
$discount_high[1]=0.10;
$discount_high[2]=0.15;

$type_low[0]=25;
$type_low[1]=30;
$type_low[2]=45;
$type_low[3]=50;

$type_middle[0]=30;
$type_middle[1]=35;
$type_middle[2]=55;
$type_middle[3]=60;

$type_high[0]=46;
$type_high[1]=53;
$type_high[2]=75;
$type_high[3]=80;

$insurance[0]=5;
$insurance[1]=5;
$insurance[2]=5;
$insurance[3]=10;
$insurance[4]=10;
      
$total_price=0;
$discount=0;
$total_days=0;
$c=0;
$b=0;
$a=0;


       $total_days=(ceil($x1+$z2+$y3));
      
       $a=$total_days-(floor($z2+$y3));
       $b=$total_days-$a-(floor($y3));
       $c=$total_days-$a-$b;
      
      if ((3 <= $total_days )&& ($total_days <= 6)) //if the days are between 3 and 6
                  {$discount=1; }//25% or 35%
   if($total_days > 6)
                  {$discount=2;} //15% or 35%
      if ($a>0) {
            $total_price=(floor($total_price+ $a*$type_low[$category]*(1-$discount_low[$discount])+ ($total_days*$insurance[$category]))*100)/100;
      }
      
      if ($b>0){
      $total_price=(floor($total_price+ $b*$type_middle[$category]*(1-$discount_middle[$discount])+ ($total_days*$insurance[$category]))*100)/100;
      }
      
      if ($c>0){
            $total_price=(floor($total_price+ $c*$type_high[$category]*(1-$discount_high[$discount])+ ($total_days*$insurance[$category]))*100)/100;
                        
                        //(floor(total_price*100))/100;
      }
      
  return $total_price;
  //return discount;
}

Having creating the function that calculates the price, I wrote the code that will take the correct period and will assign the correct  arguments to the calculate function.

<form action="price_cars.php" method="post" name="form1" id="form1" onsubmit="return check(this);">
 <input name="pickupdate" type="text" size="18" id ="pickupdate" value="pick up date" class="body"/>
 <a href="javascript:showCal('Calendar3')"><img src="emver images/datebutton.jpg" alt="dates" border="0" /></a>
                 
                  <select name="pickuphours" class="body">
                    <option selected value="pickuphour"> Pick up hour</option>
                    <option value="08:00">08:00</option>
                    <option value="09:00">09:00</option>
                    <option value="10:00">10:00</option>
                    <option value="11:00">11:00</option>
                    <option value="12:00">12:00</option>
                    <option value="13:00">13:00</option>
                    <option value="14:00">14:00</option>
                    <option value="15:00">15:00</option>
                    <option value="16:00">16:00</option>
                    <option value="17:00">17:00</option>
                    <option value="18:00">18:00</option>
                    <option value="19:00">19:00</option>
                    <option value="20:00">20:00</option>
                    </select>
                  <input name="dropoffdate" type="text" size="18" value="drop off date" class="body" id="dropoffdate"/>
                  <input name="date" type="text" size="4" value="days" class="body" id="date" style="position:absolute; left: 25px; top: 353px;"/>
                 
                  <a href="javascript:showCal('Calendar4')"><img src="emver images/datebutton.jpg" alt="dates" border="0" /></a>
                 
                  <select name="dropoffhours" class="body" >
                    <option selected value="dropoffhour"> Drop off hour</option>
                    <option value="08:00">08:00</option>
                    <option value="09:00">09:00</option>
                    <option value="10:00">10:00</option>
                    <option value="11:00">11:00</option>
                    <option value="12:00">12:00</option>
                    <option value="13:00">13:00</option>
                    <option value="14:00">14:00</option>
                    <option value="15:00">15:00</option>
                    <option value="16:00">16:00</option>
                    <option value="17:00">17:00</option>
                    <option value="18:00">18:00</option>
                    <option value="19:00">19:00</option>
                    <option value="20:00">20:00</option>
                    </select>
   <input name="button"  type="image" id="button" src="emver images/quotemebutt.jpg" style="position:absolute; left: 146px; top: 354px;" />
                  </form>
                      
<?  
      
      $period[1][1]=mktime(0,0,0,4,01,2006);
      $period[1][2]=mktime(0,0,0,6,15,2006);
      $period[2][1]=mktime(0,0,0,6,16,2006);
      $period[2][2]=mktime(0,0,0,7,15,2006);
      $period[3][1]=mktime(0,0,0,7,16,2006);
      $period[3][2]=mktime(0,0,0,8,31,2006);
      $period[4][1]=mktime(0,0,0,9,01,2006);
      $period[4][2]=mktime(0,0,0,9,30,2006);
      $period[5][1]=mktime(0,0,0,10,01,2006);
      $period[5][2]=mktime(0,0,0,10,31,2006);

$pickupperiod=0;
$dropoffperiod=0;

$days[1]=0;
$days[2]=0;
$days[3]=0;
$days[4]=0;
$days[5]=0;

$a[0]=0;
$b[0]=0;
$c[0]=0;
      
//$period_time="00:00:00";

      $pickupdate= $_POST["pickupdate"];
      echo "\n pick up user: " .$pickupdate;
    $pd = explode('/', $pickupdate);
      $pickuphour= $_POST["pickuphours"];
    $ph = explode(':', $pickuphour);
      $newpickupdate = mktime($ph[0], $ph[1], 0, $pd[1], $pd[0], $pd[2]);
      
      $dropoffdate= $_POST["dropoffdate"];
      echo "\n drop off user: " .$dropoffdate;
    $dd = explode('/', $dropoffdate);
      $dropoffhour= $_POST["dropoffhours"];
    $dh = explode(':', $dropoffhour);
    $newdropoffdate = mktime($dh[0], $dh[1], 0, $dd[1], $dd[0], $dd[2]);
   
   echo "newdropoffdate: " .$newdropoffdate;
   echo "\n newpickupdate: " .$newpickupdate;

if (($period[1][1] < $newpickupdate) && ($newpickupdate < $period[1][2]))
            {
                  $pickupperiod=1;
                  echo "mpike period 1 \n";
                  //echo "\n period: ". $period[1][1];
                  //echo "\n newpickupdate: ". $newpickupdate;
                  //echo "\n period2: ". $period[1][2];
            }

if (($period[2][1] < $newpickupdate) && ($newpickupdate < $period[2][2]))
            {
                  $pickupperiod=2;
                  echo "mpike period 2";
            }      

if (($period[3][1] < $newpickupdate) && ($newpickupdate < $period[3][2]))
            {
                  $pickupperiod=3;
                  echo "mpike period 3";
            }      
            
if (($period[4][1] < $newpickupdate) && ($newpickupdate < $period[4][2]))
            {
                  $pickupperiod=4;
                  echo "mpike period 4";
                  //echo "period: ". $period[4][1];
                  //echo "newpickupdate: ". $newpickupdate;
                  //echo "period2: \n". $period[4][2];
            }
            
if (($period[5][1] < $newpickupdate) && ($newpickupdate < $period[5][2]))
            {
                  $pickupperiod=5;
                  echo "mpike period 5";
            }

if (($period[1][1] < $newdropoffdate) && ($newdropoffdate < $period[1][2]))
            {
                  $dropoffperiod=1;
                  echo "mpike drop off period 1";
            }

if (($period[2][1] < $newdropoffdate) && ($newdropoffdate < $period[2][2]))
            {
                  $dropoffperiod=2;
                  echo "mpike drop off period 2";
            }

if (($period[3][1] < $newdropoffdate) && ($newdropoffdate < $period[3][2]))
            {
                  $dropoffperiod=3;
                  echo "mpike drop off period 3";
            }

if (($period[4][1] < $newdropoffdate) && ($newdropoffdate < $period[4][2]))
            {
                  $dropoffperiod=4;
                  echo "mpike drop off period 4";
            }

if (($period[5][1] < $newdropoffdate) && ($newdropoffdate < $period[5][2]))
            {
                  $dropoffperiod=5;
                  echo "mpike drop off period 5";
            }

if ($pickupperiod-$dropoffperiod==0) {


$days[$pickupperiod]=(   ($newdropoffdate-$newpickupdate)/3600  )/24;
//$days[$pickupperiod]= datediff(d, $newdropoffdate, $newpickupdate, $dropoffhour, $pickuphour );
//echo "days[$pickupperiod]= ". $days[$pickupperiod];
//echo "newpickupdate:  ". $newpickupdate;
//echo "dropoffdate:  ". $newdropoffdate;
      }

if ($dropoffperiod-$pickupperiod==1) {

$days[$pickupperiod]=( ($period[$pickupperiod][2] - $newpickupdate)/3600 ) /24;
//$days[$pickupperiod]= datediff(d,$period[$pickupperiod][2], $newpickupdate, $period_time,$pickuphour);
$days[$dropoffperiod]=( ($newdropoffdate-$period[$newdropoffdate][1])/3600 ) /24;
//$days[$dropoffperiod]=datediff(d,$newdropoffdate, $period[$newdropoffdate][1], $dropoffhour,$period_time);
            //echo " \n". $days[$pickupperiod];
            //echo "\n ". $days[$dropoffperiod];
      }

if ($dropoffperiod-$pickupperiod==2) {

            $days[$pickupperiod]=( ($period[$pickupperiod][2] - $newpickupdate)/3600 )/24;
            $days[$dropoffperiod]=( ($newdropoffdate-$period[$newdropoffdate][1])/3600 )/24;
            $days[$pickupdate+1]=( ($period[$newpickupdate+1][2] - $period[$newpickupdate+1][1])/3600 )/24;
            
            //echo "days[$pickupperiod]= ". $days[$pickupperiod];
            //echo "days[$dropoffperiod]= ". $days[$dropoffperiod];
            
      }
      


$a[0]=$days[1]+$days[5];
$b[0]=$days[2]+$days[4];
$c[0]=$days[3];

echo "a: " . $a[0];
echo "\n b: ". $b[0];
echo "\n c: ". $c[0];
echo "\n pickupperiod: " . $pickupperiod;
echo "\n dropoffperiod: ". $dropoffperiod;

?>

Most of the code is working but the problem I get is that sometimes when the user select specific dates it displays wrong price and some times 0 price.

An example is when the user select as pick up date 25/05/2006 and drop off date: 30/06/2006 it displayed for the first category total price of   £ 533685 which is wrong.

Another example is when the user select as pick up date 28/07/2006 and drop off date 31/08/2006 it displayed for the all the categories total price of   £0 which is wrong.

I am searching so many days what might going wrong and I can’t find anything. I would appreciate If somebody could help me and provide any suggestion or ideas.

Thank you in advance,
Xenia




0
xenoula
Asked:
xenoula
  • 2
1 Solution
 
qbankCommented:
mySql db uses. yy/mm/dd date format (ie. 2006/05/09) .  take care of date format

0
 
xenoulaAuthor Commented:
I am not using a database
0
 
xenoulaAuthor Commented:
I manage to find where was the error and not it is working.
I had put wrong variables in the dates[];
0
 
CetusMODCommented:
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now