This is my first post so please correct me if somethings wrong
Basically im creating a shopping cart with the help of a guide but there is no database written in the guide so i’m not sure how to proceed. My database wont work…
Guide:
https://jameshamilton.eu/programming/simple-php-shopping-cart-tutorial
Error message
Index:
[php]<?php session_start(); ?>
- ';
$output[] = '
- "'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'
Add to cart ';
//connect mysql
mysql_connect($server, $user, $pass) or die ("Sorry, can't conect to mysql.");
//select db
mysql_select_db($db) or die ("Sorry cant select the db.");
?>
<?php
$product_id = $_GET[id]; //the product id from the URL
$action = $_GET[action]; //the action from the URL
//if there is an product_id and that product_id doesn't exist display an error message
if($product_id && !productExists($product_id)) {
die("Error. Product Doesn't Exist");
}
switch($action) { //decide what to do
case "add":
$_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id
break;
case "remove":
$_SESSION['cart'][$product_id]--; //remove one from the quantity of the product with id $product_id
if($_SESSION['cart'][$product_id] == 0) unset($_SESSION['cart'][$product_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
break;
case "empty":
unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
break;
}
?>
<?php
if($_SESSION['cart']) { //if the cart isn't empty
//show the cart
echo " - "'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'
Add to cart ';
//connect mysql
mysql_connect($server, $user, $pass) or die ("Sorry, can't conect to mysql.");
//select db
mysql_select_db($db) or die ("Sorry cant select the db.");
?>
$name | "; //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product echo "$quantity X | "; echo "$line_cost | "; echo "
Total | "; echo "$total | "; echo "|
Empty Cart | "; echo "
poducts.php
[php]
- ';
$output[] = '