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

Double check your GET variables by outputing them via echo or var_dump. Number one cause for that kind of error for me is the variables not getting posted correctly.

Thanks I've since found a code that works however I am now getting error messages. I have created a new post for this one.

Member Avatar for diafol

Try not to create a new thread on a related issue, you run the risk of alienating contributors and giving incomplete info to potential new contributors.

Sorry Diafol
I thought that was what I was supposed to do. Would you like me to continue the thread here as well? Happy to do so if that is the prefered way.
Ray

Member Avatar for diafol

No problem - don't duplicate info as it can waste contributors' time. Just provide a link in this thread to the new one.

This discussion has been continued in another thread Click Here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.