<?php
session_start();
header('Access-Control-Allow-Origin: http://www.subal-bg.com/getinfo.php http://www.subal-bg.com');
include 'config.php';
$action=$_GET['action'];
//the product id from the URL
switch ($action){
case "Add";
if(isset($_GET['id']))
{
$ID=(int)$_GET['id'];
$_SESSION['cart'][$ID]++;
$quanty =(int)$_SESSION['cart'][$ID];
$count =(int)$_GET['id']++;
// setcookie("qunaty[$count]", $quanty);
$sucssess=true;
}
break;
case "remove";
//case remove something from cart !
$ID=$_GET['id'];
$count = $_GET['id']++;
$quanty = $_SESSION['cart'][$ID]--;
if($_SESSION['cart'][$ID]==(int)0)
{
// setcookie("qunaty[$count]", NULL);
unset($_SESSION['cart'][$ID]);
}
else
{
//setcookie("qunaty[$count]", $quanty);
$sucssess=true;
}
//end this case !
break;
case "empty";
/* foreach ($_COOKIE['cart'] as $key => $value) {
setcookie("cart[$key]", "", time()-3600);
}
foreach ($_COOKIE['qunaty'] as $key => $value) {
setcookie("qunaty[$key]", "", time()-3600);
}*/
unset($_SESSION['cart']);
unset($_SESSION['qunaty']);
$sucssess==true;
$empty=true;
break;
case "purchase";
header('Location: purchase.php') ;
break;
}
?>
<table border="1">
<tr>
<th>Продукт |</th>
<th>Брой |</th>
<th>Цена </th>
</tr>
<?php
if($empty!=true)
{
foreach ($_SESSION['cart'] as $name => $value2)
{
$rs = run_q('SELECT title,price FROM post WHERE post_id='.$name);
$row = fetch_all($rs);
foreach ($row as $p)
{
echo '
<tr>
<td>'.$p['title'].'</td>';
echo '<td>';
echo $value2;
echo '</td>';
echo '
<td>'.$p['price'].'</td>
</tr>';
}
}
}
else
{
echo '<p>Количката е празна.</p>';
}
?>
</table>