thomashw Posted January 10, 2008 Share Posted January 10, 2008 Can anyone help me get this working? I'm doing a "tutorial" to create a shopping cart. This page is to actually display the contents of the cart, but I've not seen PHP coded like this before, and it's giving me an error saying "Fatal error: Call to a member function query() on a non-object." <? $id = intval($_GET['product_id']); $total = 0; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM feature_product WHERE feature_product_id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$title.' by '.$author.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: £'.$total.'</p>'; ?> Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/85381-confused/ Share on other sites More sharing options...
duclet Posted January 10, 2008 Share Posted January 10, 2008 Where is $db being set? Use print_r on it to see if you are actually getting the correct object that should have the function query. Quote Link to comment https://forums.phpfreaks.com/topic/85381-confused/#findComment-435622 Share on other sites More sharing options...
revraz Posted January 10, 2008 Share Posted January 10, 2008 You are probably missing the Functions that go with it. Quote Link to comment https://forums.phpfreaks.com/topic/85381-confused/#findComment-435624 Share on other sites More sharing options...
thomashw Posted January 10, 2008 Author Share Posted January 10, 2008 I changed $result to equal mysql_query($sql). I used print_r and it's saying "Resource id #9." Quote Link to comment https://forums.phpfreaks.com/topic/85381-confused/#findComment-435627 Share on other sites More sharing options...
duclet Posted January 10, 2008 Share Posted January 10, 2008 No, I meant print_r on $db so that you can make sure it is actually an object that contains the method query. Quote Link to comment https://forums.phpfreaks.com/topic/85381-confused/#findComment-435629 Share on other sites More sharing options...
thomashw Posted January 10, 2008 Author Share Posted January 10, 2008 You are probably missing the Functions that go with it. You're right, I was missing the functions. What a mess. Quote Link to comment https://forums.phpfreaks.com/topic/85381-confused/#findComment-435643 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.