Forum : session shopng cart
Brief description  about Online courses   join in Online courses
View vinaykumar B patil 's Profile

session shopng cart

//vinay1.php
<?php
session_start();
$_SESSION['item1']="laptops";
$_SESSION['item2']="cameras";
$_SESSION['item3']="pendrives";
?>
<html>
<body>
<h1> welcome to the shopping socket</h1>

<form name="demo" action="vinay2.php" method="post">
select first item:<select name="laptops">
<option selected>laptops</option>
<option>dell</option>
<option>sony</option>
<option>hcl</option>
<option>hp</option>
</select><br/><br/>
select second item:<select name="cameras">
<option selected>cameras</option>
<option>nikon</option>
<option>sony</option>
<option>cannon</option>
<option>kodak</option>
</select><br/><br/>
select third item:<select name="pendrives">
<option selected>pendrives</option>
<option>sandisk</option>
<option>sony</option>
<option>transcend</option>
<option>hp</option>
</select><br/><br/>
<input type="submit"/>
</form>
</body>
//vinay2.php

<?php
session_start();
echo "item no1=".$_SESSION['item1'];
echo "item no2=".$_SESSION['item2'];
echo "item no3=".$_SESSION['item3'];
?>
<html>
<body>
</body>
</html>
what wrong with this code when i click submit button it go 2 nxt page but not featch the data which i sel in dropdown???
Asked by vinaykumar B patil | Jan 13, 2011 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
you did all value of session is hard coded if you want your selected value then first get that value $_post[name] and initialize that value with session
like

$_SESSION['item1']= $_post["laptops"];

then you get the value
Jan 17, 2011