Click to See Complete Forum and Search --> : Help using sessions


xenia
05-30-2006, 05:30 AM
Hello everyone,

I have an argent problem with an e-commerce site I am developing and I would really appreciate any help that you can provide. More specific the problem is related to the function that the user adds more items to his basket
in a specific page. I am going to describe the process untill the user adds items.

The user selects an item from the page which includes a list of items (list.php) by clicking on the name of the item. The list.php has a hidden field in order to send the id of the specific item in the next page(details_items.php). The details_items.php takes the hidden id in order to display the information for the specific product. It also has two drop down menus to select the size and quantity and a button called add to basket.
The drop down menu of the size displays the available sizes of the specific item. Every size of the item has been stored in the database as separate item using unique primary key.For example let's say that the user selects the item with reference number N01(is not the primary key).The item with reference number N01 has two sizes 3 and 6. The item with size 3 has as primary key 1 and refer N01, on the other hand the item with size 6 has primary key 2 and refer N01.So every item with different size has different id's.
The same page has also another hidden field to hold the id that will be used to the next page. When the user click on the button he is been redirected to another page which stores the item in the basket(addtobasket.php). In this page exist the code where it assign the items in a session and inform the user about the number of item he just add to his basket. This page has the same interface with the details_items.php displaying the info of the product and the drop down menus (size,quantity). Meaning that the user can add another item.

The problem I have is that when the user is already in the page addtobasket.php and wants to add the item selecting differerent size or selecting more quantity it doesn't add to the basket. So when the user select the new size and click on the add to basket button is being redirected to it self and does not add to the basket.So what the user has to do is to go to the first page and select again the same item with different size which is not the proper thing.

What I would like help from you is how I can alter my code in order the user to add as many items he wants when he is in the addtobasket page.

I have tryied to user sessions but still not working.I will post my existing code:

$itemID=$_POST['itemIDdetails'];//takes the id from the hidden field in item_details.php and is used to display the same item
$ref=$_POST['refdetails'];//takes the id from the hidden field in item_details.php

$quantitymenu=$_POST['qty']; //takes the information from the drop down menu of the item_detals.php

$_SESSION['sizemenu']=Array();
$_SESSION['sizemenu'][]=$_POST['size'];

foreach($_SESSION['sizemenu'] as $i_sale_line => $i_item_id)
{


$query="select * from Items where ref='$ref' and size='$i_item_id'";
$rs=mysql_query($query);
$row=mysql_fetch_array($rs);
echo "new item id :".$row['itemID'];

<!-- start to display the details of the specifc info-->
<? $sqlcolour = "Select * from Items,Brands,Kids,Categories where Brands.brandID=Items.brandID and Items.kidID=Kids.kidID and Items.categoryID=Categories.categoryID and Items.itemID='$itemID'";


$rscolour=mysql_query($sqlcolour);
$num=mysql_num_rows($rscolour);

$c=0;
while ($c<$num){
$itemID=mysql_result($rscolour,$c,"itemID");
$brand=mysql_result($rscolour,$c,"brand_name");
$colour=mysql_result($rscolour,$c,"colour");
$category=mysql_result($rscolour,$c,"categoryname");
$size=mysql_result($rscolour,$c,"size");
$price=mysql_result($rscolour,$c,"price");
$image=mysql_result($rscolour,$c,"image_small");
$image_large=mysql_result($rscolour,$c,"image_large");
$matching1=mysql_result($rscolour,$c,"matching1");
$matching2=mysql_result($rscolour,$c,"matching2");
$matching3=mysql_result($rscolour,$c,"matching3");
$descr=mysql_result($rscolour,$c,"description");
$ref=mysql_result($rscolour,$c,"ref");
?>


<form action="addtobasket.php" method="post">

<table width="107" border="0" >
<tr>
<td width="101"><label class="generalfont">SIZE</label>
<select name="size" class="selectcriteria">
<? $querysizeselect="select DISTINCT Items.size from Items where Items.ref='$ref'";
$rssizeselect=mysql_query($querysizeselect);
while ($rowsizeselect=mysql_fetch_array($rssizeselect)){
echo "<option>$rowsizeselect[size]</option>";
}
?>
</select> </td>
</tr>
<tr>
<td><label class="generalfont">QTY</label>
<select name="qty" class="selectcriteria">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<input type="submit" name="Submit" value="add to basket" /></td>
</tr>

<tr>
<td>
<? //$_SESSION['sizemenu']=$_POST['size']; ?>
<input name="sizedetails" type="hidden" value="<? //echo $size; ?>">
<input name="itemIDdetails" type="hidden" value="<? echo $row['itemID']; ?>">
<input name="imagedetails" type="hidden" value="1<? //echo $image; ?>"></td>
</tr>
<tr><td height="40" >
<input name="branddetails" type="hidden" value="1<? //echo $brand; ?>">
<input name="colourdetails" type="hidden" value="1<? //echo $colour; ?>">
<input name="categorydetails" type="hidden" value="1<? //echo $category; ?>">
<input name="descrdetails" type="hidden" value="1<? //echo $descr; ?>">
<?
$c++;
}?>
</td>
</table>
</form>





Thanks,
Xenia

NogDog
05-30-2006, 11:39 AM
Is there a session_start() at the beginning of the code (before you start referring to the $_SESSION array)?

pcthug
05-31-2006, 01:48 AM
You should call session_start() (http://www.php.net/session_start) before anything is outputted to the browser.

xenia
05-31-2006, 04:05 AM
I have the start_session function at the begining.Actually without changing anything now it is working.

Without doing anything,i just rename the page and that's it.

Thanks for your answers,
Xenia