Jump to content

session cart help cheers.


redarrow

Recommended Posts

what i am trying to do is have sessions hold the value of cart information on one page got that go back to main page add another entry with sessions and delete what one i wont to.

 

but i can not do it in session's only can u?

 

advance thank u.

 

 

 

cart.php

 

<?php session_start();

$user=$_SESSION['user']="00001";

echo"<br><table align='center'>
<tr><td align='center'><h1>Product's For Sale</h1></tr></td></table>";

$p1="color_tv";
$pd1="tv-59684";
$pr1="1000";
$pa1="2";

$product1="product1=product1&p1=$p1&pd1=$pd1&pr1=$pr1&pa1=$pa1";

echo" <table align='center' border='4' bordercolor='black'>
<tr><td align='center'>Product:<br>$p1</tr></td>
<tr><td align='center'>Price:<br> $pr1</tr></td>
<tr><td align='center'>Refrence:<br> $pd1</tr></td><tr><td align='center'>
Amount:<br> $pa1</tr></td>
<tr><td><a href='cart_result.php?$product1'>add to basket</a></tr></td>
</table>";

$p2="hi fi";
$pd2="hifi-94857";
$pr2="500";
$pa2="6";

$product2="product2=product2&p2=$p2&pd2=$pd2&pr2=$pr2&pa2=$pa2";

echo" <br><table align='center' border='4' bordercolor='black'>
<tr><td align='center'>Product:<br>$p2</tr></td>
<tr><td align='center'>Price:<br> $pr2</tr></td>
<tr><td align='center'>Refrence:<br> $pd2</tr></td><tr><td align='center'>
Amount:<br> $pa2</tr></td>
<tr><td><a href='cart_result.php?$product2'>add to basket</a></tr></td>
</table>";




echo"<br><br><table align='center' border='4' bordercolor='black'>
<tr><td align='center'><a href='cart_result.php?user=$user&i=$item&r=$refrence&p=$price'>view my current basket</a> </tr></td>
<table>";

?>

 

cart_result.php

<?php session_start();

$user=$_GET['user']=="00001";

if( ($_GET['product1']=="product1") || ($_GET['product2']=="product2") || ($user) ){

$item=$_GET['p1']=$p1;
$i=$_SESSION['i']=$item;
$i=$_GET['i'];


$refrence=$_GET['pd1']=$pd1;
$r=$_SESSION['r']=$refrence;
$r=$_GET['r'];

$price=$_GET['pr1']=$pr1;
$p=$_SESSION['p']=$price;
$p=$_GET['p'];

//number two

$item2=$_GET['p2']=$p2;
$i2=$_SESSION['i2']=$item2;
$i2=$_GET['i2'];


$refrence2=$_GET['pd2']=$pd2;
$r2=$_SESSION['r2']=$refrence2;
$r2=$_GET['r2'];

$price2=$_GET['pr2']=$pr2;
$p2=$_SESSION['p2']=$price2;
$p2=$_GET['p2'];

echo"<table align='center' border='4' bordercolor='black'>
<tr><td align='center'>
Item for sale
<br>
$item $i
<td align='center'>
Item refrence
<br>
$refrence $r
</td>
<td align='center'>
Item price
<br>
$$price $p
</td>";
?>

<?php if($user){ ?>

<td><a href='cart_result.php?cmd=del'>delete</a>

</td>

<?php
}
echo"</tr></table>";


if($_GET['cmd']=="del"){

unset($i);
unset($r);
unset($p);

echo"<table align='center' border='4' bordercolor='black'>
<tr><td align='center'>
Entry DELETED
</tr></td></table>";
}


// two

echo"<table align='center' border='4' bordercolor='black'>
<tr><td align='center'>
Item for sale
<br>

$item2";

?>

<?php if($user){
echo $i2;
}
?>

<?php
echo"
<td align='center'>
Item refrence
<br>
$refrence2";
?>

<?
if($user){
echo $r2;
}
?>

<?php
echo"
</td>
<td align='center'>
Item price
<br>
$$price2"; 
?>


<?php

if($user){
echo $pr2;
}

echo"</td>";

?>

<?php if($user){ ?>

<td><a href='cart_result.php?cmd2=del2'>delete</a>

</td>

<?php

echo"</tr></table>";
}

if($_GET['cmd2']=="del2"){

unset($i2);
unset($r2);
unset($p2);

echo"<table align='center' border='4' bordercolor='black'>
<tr><td align='center'>
Entry DELETED
</tr></td></table>";
}
}

?>

Link to comment
https://forums.phpfreaks.com/topic/38872-session-cart-help-cheers/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.