I am making a shopping cart app(small) and have run into a problem
The add to Cart Page
<?php echo "". $_SESSION['products'] .""?><?php
$id = $_GET['id'];
$products=$_SESSION['products'];
$products="$id"; //Load session variable to a regular page variable
$products['']="". $_SESSION['products'] .""; //Add a new product ID to the array
$_SESSION['products']=$products; //Put the new updated array back into the session.
$product="$id";
echo $products;
?>
the veiwcart page
<?php
// viewCart.php
include 'config.php';
// Using cranial-bore's suggestion of array in session
// $_SESSION["products"] = array(145, 193, 223);
$_SESSION["products"] = array("". $_SESSION['products'] ."");
// Loop through and get all ids
for($item = 0; $item < count($_SESSION['products']); $item++){
// Get data for current item id
$sql = "SELECT * FROM products WHERE id = ". $_SESSION["products"][$item];
$query = @mysql_fetch_array(@mysql_query($sql)) or die(print mysql_error());
// Set you fields here
list($id, $price) = $query;
// Display the product information
echo $id. "--". $price. "--". "<a href=\"remove.php?id=$id\" onClick=\"return popitup('remove.php?id=$id')\"><img src=\"i_delete.gif\" alt=\"Remove $pid From Cart\" width=\"16\" height=\"16\" border=\"0\"><br></a>";
}
echo "hi $products";
?>
With the echo $products in both of the pages all i get is Array.
Therfor in teh $sql query on veiwcart page it cannot find the tcolumn 'array', as it should be the product ID(the variable set)
Unknown column 'Array' in 'where clause'
Can anyone show me why this is not working?
Cheers