Issues with displaying Info

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aolle34
Forum Newbie
Posts: 4
Joined: Mon Dec 16, 2013 10:13 am

Issues with displaying Info

Post by aolle34 »

I'm making a simple shopping cart application. The main page displays a list of products.When you click on the name of the product, it should take you to a page where just that product info is displayed. Right now, it's not displaying anything. Here's my code:

Code: Select all

<?php

    $sql = "SELECT product_id, image_path, name, description, price FROM products;";
    $result = mysql_query($sql);
    while(list($product_id, $image_path, $name, $description, $price) = mysql_fetch_row($result)) {

        echo "<tr>";
            echo "<td><img src=$image_path height=200 width=160 border=1px /></td>";
            echo "<td><b><a href=\"getprod.php?product=" .
                  $product_id['product_id'] . "\">$name</a></b><br/ >";
            echo "$description<br/ >";
            echo "$$price<br/ >";
            echo "<input type='button' value='Add to Cart' onclick='addtocart'/>"; 

        echo "</tr>";

    }

?>
And my productInfo method that is supposed to display my info:

Code: Select all

function productInfo($product_id) {
    global $conn;

    if($product_id) {
        $sql= "SELECT product_id,image_path, name, description, price " . 
              "FROM products WHERE product_id = " . $product_id; " . 

        $result= mysql_query($sql, $conn) or
            die('Could not find product info: ' . mysql_error());

        while(list($product_id, $image_path, $name, $description, $price) = mysql_fetch_row($result)) {
            echo "<td><img src=$image_path height=200 width=160 border=1px /></td>";
            echo "<td><b><a href=\"getprod.php?product=" .
                  $product_id['product_id'] . "\">$name</a></b><br/ >";
            echo "$long_description<br/ >";
            echo "$$price<br/ >";
            echo "<input type='button' value='Add to Cart' onclick='addtocart'/>"; 
        }

        }
    }
Any help is much appreciated!!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Issues with displaying Info

Post by Celauran »

Code: Select all

$sql= "SELECT product_id,image_path, name, description, price " . 
              "FROM products WHERE product_id = " . $product_id; " . 
What's going on with that last " . ? That's certainly going to cause problems.
aolle34
Forum Newbie
Posts: 4
Joined: Mon Dec 16, 2013 10:13 am

Re: Issues with displaying Info

Post by aolle34 »

Not sure how that got there. Pasting error I guess. It ends at " . $product_id;
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Issues with displaying Info

Post by Celauran »

Right now, it's not displaying anything
Do you have error reporting enabled?

Code: Select all

list($product_id...
$product_id['product_id']
You sure about that?
aolle34
Forum Newbie
Posts: 4
Joined: Mon Dec 16, 2013 10:13 am

Re: Issues with displaying Info

Post by aolle34 »

Error reporting is enabled....not getting any errors. And I'm not sure about anything at this point, just looking for answers and help in getting there. I gotta run for a few hours, but I will check back later. This project is due tomorrow so I don't plan on sleeping tonight unfortunately. Thank you for the replying though!
Post Reply