Jump to content

Session is being overwritted


xenia

Recommended Posts

Hello,

I have developed a website for a car rental company in which the user can select the pickup date and drop off date and can see a list of all the cars with their price depending on the selected date.The user select one car and is being redirected to an enquiry form in order to complete his personnal details in order the company to communicate with the customer and inform him if the specific car is availabel or not.

In the page(enquiry_form.php) with the enquiry form I am displaying the pickup dates/hour and drop off dates/hour that the use has select from the previous page(quote.php)which I have save them in sessions in the page quote.php.Using the sessions I manage to keep the information for the dates even if the user submit as many times the form(I have put error validation).

What I am trying to do now is to display also the information for the specific car that the user selected.More specific the image ,model and price.In the page quote.php that the cars are listed ,every car I have put it in a different form and the information for the image ,model and price I save them in sessions.Totally are 8 cars so I have put 8 forms and in every form I have put manually the image of the car,the price from a php function I created for calculating the price,and the model (I do not use database,as it is static).

In the page enquiry_form.php I call the sessions in order to display the image and the price.

The problem I have is that when the user select one of the cars(quote.php) and go to the next page enquiry_form is going to display
the image and price of the last car.Thus,it maybe the session overwrites all the other cars and display the latest.

The site map of the website is the following:

index.php->quote.php->enquiry_form.php

I will post also my code and I would be greatfull if you could help me.
[code=php:0]
<!-- quote.php -->

<?
session_start();

//assign the pick up drop off details in sessions and i will use them in all the other pages
$_SESSION['pickupdate']=$_POST['pickupdate'];
$pickupdate=$_SESSION['pickupdate'];
$_SESSION['pickuphours']=$_POST['pickuphours'];
$pickuphours=$_SESSION['pickuphours'];
$_SESSION['pickupmin']=$_POST['pickupmin'];
$pickupmin=$_SESSION['pickupmin'];
$_SESSION['dropoffdate']=$_POST['dropoffdate'];
$dropoffdate=$_SESSION['dropoffdate'];
$_SESSION['dropoffhours']=$_POST['dropoffhours'];
$dropoffhours=$_SESSION['dropoffhours'];
$_SESSION['dropoffmin']=$_POST['dropoffmin'];
$dropoffmin=$_SESSION['dropoffmin'];

<table width="675" border="0" cellpadding="0" cellspacing="0">
<tr>
<td > </td>
<td >Car Type</td>
<td >Car Info </td>
<td >Capacity </td>
<td > </td>
<td >Price</td>
<td >Email Quote </td>
</tr>
<tr>
<td > </td>
<td ><img src="smartfourtwo.jpg" alt="smart for two" /></td>
<td > </td>
<td >

<!--The information for the first car -->
<form id="form8" name="form8" method="post" action="enquiry_form.php" >
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td >€
<?
$price8= calculate($a[0],$b[0],$c[0],1);

echo $price8;

?>
</span></td>
<td ><?

$_SESSION['price']=$price8;
$price8= $_SESSION['price'];
$_SESSION['image']="smartfourtwo.jpg";
$image=$_SESSION['image'];
$_SESSION['model']= "Smart four two";
$model=$_SESSION['model'];
?></td>
<td width="40"><input name="price8" type="hidden" value="<? echo $_SESSION['price']; ?>" /></td>
<td width="84"><input name="Submit" type="image" value="Book" src="book1.jpg" width="65" height="25" /></td>
</tr>
</table>
</form></td>
</tr>


<!--The information for the second car -->
<tr >
<td > </td>
<td ><img src="suzukialtob.jpg" width="330" height="92" /></p></td>
<td > </td>
<td >
<form id="form2" name="form2" method="post" action="enquiry_form.php" >
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="36" class="body">€
<?
$price= calculate($a[0],$b[0],$c[0],0);

echo $price;

?> </td>
<td width="40"><?

$_SESSION['price'][]=$price;
$price= $_SESSION['price'];
$_SESSION['image']="suzukialtob.jpg";
$image=$_SESSION['image'];
$_SESSION['model']= "Suzuki Alto";
$model=$_SESSION['model'];

?></td>
<td width="40"><!--<input name="price" type="hidden" value="<? //echo $_SESSION['price']; ?>" />--></td>
<td width="84"><input name="Submit" type="image" value="Book" src="book1.jpg" width="65" height="25" /></td>
</tr>
</table>
</form></td>
</tr>

<tr>
<td class="quotetable"> </td>
<td colspan="3" class="quotetable"><img src="suzukiswiftb.jpg" width="330" height="92" /></td>
<td class="quotetable"> </td>
<td colspan="2" valign="middle" class="quotetable">
<form id="form3" name="form3" method="post" action="enquiry_form.php" >
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="36" class="body"> €
<?
$price2= calculate($a[0],$b[0],$c[0],0);

echo $price2;

?></td>
<td width="40">
<?



$_SESSION['price']=$price2;
$price2= $_SESSION['price'];
$_SESSION['image']="fiatseicento.jpg";
$image=$_SESSION['image'];
$_SESSION['model']= "Fiat Seicento";
$model=$_SESSION['model'];

?> </td>
<td width="40"> <input name="price" type="hidden" value="<? echo $price2; ?>" /></td>
<td width="84">
<input name="Submit" type="image" value="Book" src="book1.jpg" width="65" height="25" /></td>
</tr>
</table>
</form> </td>
</tr>



<tr>
<td > </td>
<td ><img src="daewoomatiz.jpg" width="330" height="92" /></td>
<td > </td>
<td >
<form id="form5" name="form5" method="post" action="enquiry_form.php" >
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="36" class="body">€
<?
$price4= calculate($a[0],$b[0],$c[0],0);

echo $price4;

?> </td>
<td width="40">
<?


$_SESSION['price']=$price4;
$price4= $_SESSION['price'];
$_SESSION['image']="daewoomatiz.jpg";
$image=$_SESSION['image'];
$_SESSION['model']= "Daewoo Matiz";
$model=$_SESSION['model'];
?></td>
<td width="40"> <input name="price" type="hidden" value="<? echo $_SESSION['price']; ?>" /></td>
<td width="84"><input name="Submit" type="image" value="Book" src="book1.jpg" width="65" height="25" /></td>
</tr>
</table>
</form></td>
</tr>




<tr>
<td class="quotetable"> </td>
<td colspan="3" class="quotetable"><br>
<span class="bodytitlesmall"><a href="quote.php#top" class="bodytitlesmall">> Return to top of Page</a><br>
<br>
</span></td>
<td class="quotetable"> </td>
<td class="quotetable"> </td>
<td class="quotetable"> </td>
</tr>
</table>


<!-- enquiry_form.php -->
<? session_start(); ?>
<table width="380" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td ><label>Pick up date:</label></td>
<td ><? echo $pickupdate; ?></td>
<td ><? echo $pickuphours; ?> : <? echo $pickupmin; ?></td>
<td ><label>Price:</label></td>
<td >€ <? echo $price; ?></td>
</tr>
<tr>
<td ><label>Drop off date:</label></td>
<td ><? echo $dropoffdate; ?></td>
<td><? echo $dropoffhours; ?> : <? echo $dropoffmin; ?></td>
<td> </td>
<td> </td>
</tr>
</table>
[/code]

Thank you in advance,
Xenia
Link to comment
Share on other sites

I think you just need to redesign the whole method but it's hard to understand the purpose of the code from the long post

you should think of using a database to store the car data and then all you have to do is add the last viewed cars as car_id. this would simply the whole process. then you can just query the car data from the database in the form.
Link to comment
Share on other sites

[!--quoteo(post=384499:date=Jun 16 2006, 03:51 AM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 16 2006, 03:51 AM) [snapback]384499[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I think you just need to redesign the whole method but it's hard to understand the purpose of the code from the long post

you should think of using a database to store the car data and then all you have to do is add the last viewed cars as car_id. this would simply the whole process. then you can just query the car data from the database in the form.
[/quote]

Thank you for your suggestion joquius.I cannot use a database as the customer prefers not to have.
However, I manage to solve it.

Instead of making all these sessions on page quote i make

<input type="hidden" name="price" value="<?php echo $price8;?>">
<input type="hidden" name="image" value="smartfourtwo.jpg">
<input type="hidden" name="model" value="Smart four two">

and on the next page enquiry_from.php

I put
if(isset($_POST['price'])){
$_SESSION['price']=$_POST['price'];
}
if(isset($_POST['image'])){
$_SESSION['image']=$_POST['image'];
}
if(isset($_POST['model'])){
$_SESSION['model']=$_POST['model'];
}

thanks,
Xenia

Link to comment
Share on other sites

You're use of sessions is fine as long as the user has a browser window open, but without someway of permently storing the information, other users will not see the changes to the inventory. And as soon as the browser window is closed and changes made will be lost.

In other words, you need to convince the client that some sort of permenant storage is needed -- a database or a flat file. Using a database is preferrable, since the database application will take care of multiple accesses to the data. If you use a flatfile, you need to take care of what happens during concurrent accesses.

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.