Meadows Posted June 16, 2013 Share Posted June 16, 2013 Hi All, I'm creating a shopping cart from following a tutorial online from TheTutSpace: http://www.youtube.com/watch?v=AKSkvZHJIEw&list=PLBA98B91CBF08F3A2 I have gotten up to the page where the cart should be displaying the products that have been added to the cart, and "Go To Cart" has been clicked. The page loads up correctly, however doesn't display any of the products that have been added to the cart. I know its storing them correctly as they are visible in the sidebar, they just aren't echoing out properly it seems. I have also ran var_dump on $sql and $query, both returning the results that are expected of them. The cart connects to the DB via a require_once which is located on my index.php so theres no issues there. I have attached the cart.php page (which seems to be the only issue) If you require more information, please do ask and i'll provide as much as i can! The section i THINK is the issue is: if(!empty($query)){ while($row = mysql_fetch_array($query)){ $subtotal = $_SESSION['cart'][$row['SKU']]['quantity']*$row['price']; $total_price += $subtotal; ?> <tr> <td><?php echo $row['name']; ?></td> <td><input type="text" name="quantity-<?php echo $row['SKU']; ?>" size="5" value="<?php echo $_SESSION['cart'][$row['SKU']]['quantity']; ?>" /></td> <td><?php echo "£" . $row['price']; ?></td> <td><?php echo "£" . $_SESSION['cart'][$row['SKU']]['quantity']*$row['price']; ?></td> </tr> <?php } }else { echo "<i>No Items founds to display!</i> "; } ?> I am new to PHP as you may have guessed, so please be kind cart.php Link to comment https://forums.phpfreaks.com/topic/279239-phpmysql-coding-help-needed/ Share on other sites More sharing options...
Barand Posted June 16, 2013 Share Posted June 16, 2013 Use mysql_num_rows($query) to see if any rows were found Link to comment https://forums.phpfreaks.com/topic/279239-phpmysql-coding-help-needed/#findComment-1436267 Share on other sites More sharing options...
Meadows Posted June 16, 2013 Author Share Posted June 16, 2013 Have just ran $querycheck = mysql_num_rows($query); echo $querycheck; and nothing was output, nothing changed Link to comment https://forums.phpfreaks.com/topic/279239-phpmysql-coding-help-needed/#findComment-1436272 Share on other sites More sharing options...
Barand Posted June 16, 2013 Share Posted June 16, 2013 Have you got error reporting on? Have you you checked what mysql_error() returns after running the query? Link to comment https://forums.phpfreaks.com/topic/279239-phpmysql-coding-help-needed/#findComment-1436273 Share on other sites More sharing options...
Meadows Posted June 16, 2013 Author Share Posted June 16, 2013 Unknown column 'test1' in 'where clause' Is the die message i get on that query Link to comment https://forums.phpfreaks.com/topic/279239-phpmysql-coding-help-needed/#findComment-1436275 Share on other sites More sharing options...
Barand Posted June 16, 2013 Share Posted June 16, 2013 Then fix it. You are either referencing a non-existent column or you have a string value in your query containing "test1" that is not inside quotes. We haven't even seen the query, let alone your table structures, so your pretty much on your own, unless we have a psychic in or midst. Link to comment https://forums.phpfreaks.com/topic/279239-phpmysql-coding-help-needed/#findComment-1436281 Share on other sites More sharing options...
Meadows Posted June 16, 2013 Author Share Posted June 16, 2013 Hi there, I've fixed the issue, it seemed that the variable $sql query was incorrect as the $id is strings and not numbers. Fixed with: foreach ($_SESSION['cart'] as $id => $value) { $sql .="'" . mysql_real_escape_string($id) . "',"; } Link to comment https://forums.phpfreaks.com/topic/279239-phpmysql-coding-help-needed/#findComment-1436286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.