Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007

    Unanswered: "Add to cart" troubles

    My "Add to Cart" button is not working.
    If I open phpMyAdmin and add items into the Cart table these will display when I click "Add to Cart". I can't add anything else to the cart from the viewbooks.php page. If I empty the table and then try to click an item to "Add to Cart" -also nothing. No error messages occur either.

    I can run all my SQL queries in phpMyAdmin SQL screen and they work.

    I'd like to buy a clue regarding where this problem is located. Is it the viewbooks.php page (i.e where the Add to cart button is located) or the addtocart.php page?
    The only relevant info on the viewbooks page (i think)
    <form method="post" action="addtocart.php">
    <table class="aatable">
    <th>Book Id</th><td><?php print($productid); ?></td>
    <th>Author</th><td><?php print($bkauthor); ?></td>
    <th>Title</th><td><?php print($bktitle); ?></td>
    <th>Publication Year</th><td><?php print($bkpubyear); ?></td>

    <input type="submit" value="Add to cart"/>
    <input type="hidden" name="Book_ID" value="<?php print ($productid)?>"/>

    <!--body ends-->

    This is the addtocart page


    header('Location: login.php');

    $custcart = $_SESSION['customer'];

    function addToCart($prodid,$custid){
    $cust = new customer();

    $table=$cust->getData("select qty from Cart where cid=".$custid." and Book_ID=".$prodid);
    //if this item exists in customers cart update qty by 1
    $qty = $row['qty']+1;
    $qry="update Cart set qty=".$qty." where cid=".$custid." and Book_ID=".$prodid;
    //no rows return so add or insert item into customers cart
    $qry="insert into Cart (qty,cid,Book_ID) values(1,".$custid.",".$prodid.")";

    $con = new mysqli($cust->databaseURL(),
    function getCart($custid){
    $qry="SELECT books.Book_ID, Title, Price, qty, SUM( Price * qty ) AS subtotal
    FROM books
    INNER JOIN Cart ON Cart.Book_ID = books.Book_ID
    AND Cart.cid=".$custid."
    GROUP BY Book_ID, Title, Price, qty";
    $config = new conf();
    $con= new mysqli($config->databaseURL(),
    $table = $con->query($qry);
    while ($row=$table->fetch_array()){
    echo "<form method='post' action='updatecart.php'>";
    echo "<tr>";
    echo "<td>".$row['Title']."</td>";
    echo "<td>".$row['Price']."</td>";
    echo "<td>";
    echo "</td>";
    echo "<td>".$row['subtotal']."</td>";
    echo "<td><input type='hidden' name='Book_ID' value='".$row['Book_ID']."'/><input type='submit' value='update'/></td>";
    echo "<tr>";
    echo "</form>";

    function createSelectBox($optNum,$selected,$name,$width){
    echo "<select name='".$name."' style='width:".$width.";'>";

    if($selected > 5){
    $selected = 5;
    echo "<option value='".$i."' selected >".$i."</option>";
    echo "<option value='".$i."'>".$i."</option>";

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">

    <html xmlns="">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="itinerary, list" />
    <meta name="description" content="This page provides a list of all itineraries" />
    <link href="css/default.css" rel="stylesheet" type="text/css" />

    <div id="wrapper">
    <?php include 'incs/header.php'; ?>
    <!-- end div#header -->
    <div id="page">
    <div id="content">
    <div id="welcome">
    <h1>Your cart</h1>

    <table class="aatable">
    <?php getCart($custcart); ?>


    <!--body ends-->

    <!-- end div#welcome -->

    <!-- end div#content -->
    <div id="sidebar">
    <?php include 'incs/nav.php'; ?>
    <!-- end navigation -->
    <?php include 'incs/updates.php'; ?>
    <!-- end updates -->
    <!-- end div#sidebar -->
    <div style="clear: both; height: 1px"></div>
    <?php include 'incs/footer.php'; ?>
    <!-- end div#wrapper -->

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    what error reporting level are you using
    its very difficult to diagnoise such faults remotely
    what have you changed recently
    id want to check the response form any insert statements
    if want to check if the session variable are being intialised correctly
    id want to put debug statements dispalying relevant information

    id consider using something like the eclipse environment
    Last edited by StealthRT; 07-26-08 at 20:34.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2007
    I'm using Eclipse, although in the short course on PHP and MySQL our lecturer/teacher showed it to us but not specifically how to debug or so much error reporting.
    The best I can do is that if I run the viewbooks.php page in the "Debug as PHP web page" I get the "Call to a member function on a non-object error" as per my previous post. I don't get this when I run the page directly outside of Eclipse. - and it works I see the books displayed.
    I don't know how to check this properly. I can take out the sql to run elsewhere but I don't know how to check whether my php variables do what they are supposed to.
    I'm reading the Eclipse documentation and I hope that the debugging perspective might help me but in the interim if you know why I would only get that error in the debug but not when just running the page...

  4. #4
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    what makes you think its a SQL problem?
    the error message you are referring to suggests its a PHP problem with intialising the class, or initialising variables.

    id want to go through line by line to make certain that what the PHP script is interpreting is what you think it should be
    one thing you can do is print out the SQL you are actaully sending to the server and compare it to what you think you should be sending.
    print out the results of any conditional statements, so you know where the code is branching
    check what error code / error_reporting level you are using. bear in mind your server may be set to a more production friendly error_level which hides some errors. in a development environment ideally you want to smoke out any/all errors
    there is a reasoanbly good description of how to use PHP in the Eclipse environment which I got from the IBM site a while back... there's 6million + hits for PHP eclipse debugging on google
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts