Jump to content

luckyirish470

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

luckyirish470's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you very much for the quick reply! I really appreciate it! Unfortunately I just tried changing the $_GET[productname] to $cat_id and it didn't seem to alter the functionality of the script. Thank you very much anyways though! Adam
  2. Hello, I'm trying to create a simple database driven shopping cart that merely displays the selected items and adds up the total price. I think the error is in my $_SESSION variable but for the life of me I can't figure out what it is. Right now the script can tell the number of items the user has put in the cart, but the script just displays the last item added to the cart over and over again regardless of whether or not the user selects different items(the number of times the item is displayed is equal to the number of total items the user has placed in the cart) The total price calculation is working, but it is adding the prices for the same item over and over again (once again, this item that is displayed repeatedly is last item the user added to the cart) When I run the "print $_SESSION[items]' at the top of the code, the only thing that is displayed is "Array." Any ideas where I'm going wrong? Thank you very much in advance! Here is the code that gets the information for the actual shopping cart. This script displays the items the users can select to put in their shopping cart... ........................................................................ <?php session_start(); if(!isset($_SESSION['auth']) or $_SESSION['auth'] != "yes") { header("location: loginfinal.php"); header('Content-type: image/jpg'); exit(); } ?> <?php /* Program name: page_links.inc * Description: file builds a list of links from the database */ ini_set("display_errors","on"); error_reporting(E_ALL | E_STRICT); ini_set("include_path","./includes"); ?> <html> <head><title>Customer Products</title></head> <body> <?php include("dbinfo.inc"); $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("couldn't connect to server"); $query = "SELECT * FROM products WHERE category='$_GET[category]'"; $result = mysqli_query($cxn,$query) or die("Couldn't execute query ".mysqli_error($cxn)); while($row = mysqli_fetch_assoc($result)) { extract($row); echo " <ul><li> <img src='images/$thumbnail'/> <br /> <a href='shoppingcart.php?productnumber=$productnumber&thumbnail=$thumbnail&productname=$productname&price=$price'>$productname </a><br /> $description <br/> \$$price </li> </ul>"; } ?> </body></html> ... End first script ... Now here is the actual shopping cart script... <?php session_start(); if(!isset($_SESSION['auth']) or $_SESSION['auth'] != "yes") { header("location: loginfinal.php"); exit(); } ?> <?php print $_SESSION[items]; /* Program name: shoppingcart.inc * Description: file builds a list of links from the database */ ini_set("display_errors","on"); error_reporting(E_ALL | E_STRICT); ini_set("include_path","./includes"); ?> <html> <head><title>Shopping Cart</title></head> <body> <?php $total=0; include("dbinfo.inc"); $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("couldn't connect to server"); if(!isset($_SESSION['items'])) { $_SESSION['items'] = array('productnumber'=>'$productnumber', 'thumbnail'=>'$thumbnail', 'productname'=>'$productname', 'price'=> '$price'); } $_SESSION['items'][] = $_GET['productnumber']; foreach($_SESSION['items'] as $cat_id) { $query = "SELECT * FROM products WHERE productnumber='$_GET[productnumber]'"; $result = mysqli_query($cxn,$query) or die("Couldn't execute query ".mysqli_error($cxn)); while($row = mysqli_fetch_assoc($result)) { extract($row); echo " <ul><li> <img src='images/$_GET[thumbnail]'/> <br /> $_GET[productname] <br/> \$$_GET[price] </li> </ul>"; $total= $total + $price; } } ?> <?php echo" <h3> Total Price </h3> \$$total <br /> <a href='thankyou.php'>Submit Order </a> <a href='products.php?total=$total'>Keep Shopping </a>"; ?> </body> </html> ... Here is a link to the live site....http://notestotheman.com/php/lesson6/finalcountdown/loginfinal.php username=bambi password=1234567
  3. Thank you for the reply, I just tried the print $_SESSION[items]; and the only thing that was displayed was "Array". Any idea where I'm going wrong? Thanks again!
  4. Hello, I'm trying to get my shopping cart script to display the item picture, info, and price for every item selected while calculating a total price for all the items as the cart is updated. The two related scripts are in .inc files and everything looks right to me...but when I run the scripts nothing is displayed and the total price displayed is $0. I am using $_SESSION variables and my guess is I've done something wrong with them...but I have been staring at the code for weeks now trying to figure out what it is and I am running out of hair to pull out! Any help would be GREATLY appreciated, thank you! Here are the script .inc files.... ------------------------------------------------------------------------------------------------------ PRODUCT DISPLAY PAGE...... ------------------------------------------------------------------------------------------------------ <?php session_start(); if(!isset($_SESSION['auth']) or $_SESSION['auth'] != "yes") { header("location: loginfinal.php"); header('Content-type: image/jpg'); exit(); } ?> <?php /* Program name: page_links.inc * Description: file builds a list of links from the database */ ini_set("display_errors","on"); error_reporting(E_ALL | E_STRICT); ini_set("include_path","./includes"); ?> <html> <head><title>Customer Products</title></head> <body> <?php include("dbinfo.inc"); $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("couldn't connect to server"); $query = "SELECT * FROM products WHERE category='$_GET[category]'"; $result = mysqli_query($cxn,$query) or die("Couldn't execute query ".mysqli_error($cxn)); while($row = mysqli_fetch_assoc($result)) { extract($row); echo " <ul><li> <img src='images/$thumbnail'/> <br /> <a href='shoppingcart.php?productnumber=$productnumber&thumbnail=$thumbnail&productname=$productname&price=$price'>$productname </a><br /> $description <br/> \$$price </li> </ul>"; } ?> </body></html> ------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------ SHOPPING CART SCRIPT ------------------------------------------------------------------------------------------------------ <?php session_start(); if(!isset($_SESSION['auth']) or $_SESSION['auth'] != "yes") { header("location: loginfinal.php"); exit(); } ?> <?php /* Program name: shoppingcart.inc * Description: file builds a list of links from the database */ ini_set("display_errors","on"); error_reporting(E_ALL | E_STRICT); ini_set("include_path","./includes"); ?> <html> <head><title>Shopping Cart</title></head> <body> <?php $total=0; include("dbinfo.inc"); $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("couldn't connect to server"); if(!isset($_SESSION['items'])) { $_SESSION['items'][]= array('productnumber'=>'$productnumber', 'thumbnail'=>'$thumbnail', 'productname'=>'$productname', 'price'=> '$price'); $items = $_SESSION['items']; } foreach($_SESSION['items'] as $productnumber) { $query = "SELECT * FROM products WHERE productnumber='$_SESSION[items]'"; //should be $_Get[productnumber] $result = mysqli_query($cxn,$query) or die("Couldn't execute query ".mysqli_error($cxn)); while($row = mysqli_fetch_assoc($result)) { extract($row); echo " <ul><li><img src='images/$_SESSION[thumbnail]'/> <br /> $_SESSION[productname] <br/> \$$_SESSION[price] </li> </ul>"; $total= $total + $price; } } ?> <?php echo" <h3> Total Price </h3> \$$total <br /> <a href='thankyou.php'>Submit Order </a> <a href='products.php?total=$total'>Keep Shopping </a>"; ?> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.