tet3828 Posted December 14, 2006 Share Posted December 14, 2006 I'm currently trying to inturpret and re-write a shopping cart script to integrate it into my site.I am having a very hard time comprehending the script even though it came with a decent help file. This portion of the script is intended to display the cart after an item is added I take.How ever after I use my "add item" button in my script I get this error...Reffering to the line of code commented below. The error:[code]Fatal error: Call to a member function on a non-object in /home/content/t/e/t/tetunity/html/shell/data/shop.php on line 186[/code][b]I've paced a comment on line 186[/b]....What is causing this error?... pls help. thx freaksThe script:[code]$total = 0;$output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT itemName,itemCat,itemSub,itemId,itemPrice,itemDesc,itemSmall FROM products WHERE itemId='.$id; $result = $db->query($sql); ///<----this line is getting the error $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>';[/code] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 14, 2006 Share Posted December 14, 2006 at that point in the script has the $db object been initialized?In other words, have you created a new database object and assigned it to the $db variable...[code]$db = new database();[/code] Quote Link to comment 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.