Dysan Posted November 16, 2007 Share Posted November 16, 2007 On executing the code below, an error message appears. Why is this? Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\User\Desktop\Xampp\htdocs\cart.php on line 51 $total = 0; echo '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM books WHERE id = '.$id; $result = mysql_query($sql); $row = mysql_fetch_array($result); echo '<tr>'; echo '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; echo '<td>'.$row['title'].' by '.$author.'</td>'; echo '<td>£'.$price.'</td>'; echo '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; echo '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; echo '</tr>'; } echo '</table>'; echo '<p>Grand total: £'.$total.'</p>'; echo writeShoppingCart(); echo '<a href="cart.php?action=add&id=1">Add to cart</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/77673-shopping-cart-not-working/ Share on other sites More sharing options...
alecks Posted November 16, 2007 Share Posted November 16, 2007 print $result and see what it comes out with, it is probably returning (I think your query is incorrectly formatted) $sql = "SELECT * FROM `books` WHERE `id` = '$id'"; $result = mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/77673-shopping-cart-not-working/#findComment-393217 Share on other sites More sharing options...
Dysan Posted November 16, 2007 Author Share Posted November 16, 2007 Can data in the database be displayed without using a while loop. Obviously only one record will get displayed. mysql_select_db("db", $con); $result = mysql_query("SELECT * FROM details"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/77673-shopping-cart-not-working/#findComment-393223 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.