Hi
I'm built a fairly basic add to shortlist function on my website similar to a session based add to cart.
Here is the code for my add to shortlist button.
<a href = "http://www.website.com/cart.php?action=add&id=' . $id . '" <b>Add to Shortlist<b> </a>
Here is the code for my cart page.
`<?php
// Start the session
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><style type="text/css">
<!--
body {
background-color: #E8E1C3;
}
-->
</style>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="styles.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".flip").click(function(){
$(this).next('.panel').slideToggle('slow');
});
});
</script>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php include("header_1.php");
include("header.php");
include("heading.php");
include ("Connections/database.php");
?>
<div id='content'><div id='output'>
<?php
if (isset($_GET['id']))
$id=$_GET['id'];
else
$id=1;
if (isset($_GET['action']))
$action=$_GET['action'];
else
$action='empty';
switch($action)
{
case 'add':
if (isset($_SESSION['cart'][$id]))
$_SESSION['cart'][$id]++;
else
$_SESSION['cart'][$id]=1;
break;
case 'remove':
if (isset($_SESSION['cart'][$id]))
{
$_SESSION['cart'][$id]--;
if ($_SESSION['cart'][$id]==0)
unset($_SESSION['cart'][$id]);
}
break;
case 'empty':
unset($_SESSION['cart']);
break;
}
/*Display cart*/
if (isset($_SESSION['cart']))
{
foreach($_SESSION['cart'] as $id)
{
$result = mysql_query('SELECT * FROM test WHERE id= '. $id .' ');
$row = mysql_fetch_array($result);
}
if($result === FALSE) {
die(mysql_error());
}
while($row = mysql_fetch_array($result))
{
echo $row['name'];
}
}
else
echo 'Cart is empty';
?>
</div></div>
<?php include ("footer.php"); ?>
</body>
</html>`
The cart is empty message is working fine but when I add anything to the cart the results are blank. I'm sure its something simple but I can't see it.
Thanks