jmclocals Posted July 13, 2010 Share Posted July 13, 2010 Hey, Im having a problem extracting a specific ID from a MySQL database and displaying it in the form I've built. At first, I was just getting a blank page without the proper database info on the page.. Now, I'm getting a Fatal error (line 27) in my 'functions.inc.php' file. Here is my error: Fatal error: Call to undefined method MySQL::query() in /home/content/36/6079136/html/cart/inc/functions.inc.php on line 27 I posted a similar issue earlier and I didn't think before I changed a bit of my script, leaving someone who was helping me kind of lost... My fault.. Here is my script... Can someone please help me out. Thanks <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM deals WHERE 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: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/207640-fatal-error-call-to-undefined-method-mysqlquery-in-homecontent366079136/ Share on other sites More sharing options...
Maq Posted July 13, 2010 Share Posted July 13, 2010 You set $db but never define it. So trying to invoke the query() method from a null global variable doesn't make much sense. Quote Link to comment https://forums.phpfreaks.com/topic/207640-fatal-error-call-to-undefined-method-mysqlquery-in-homecontent366079136/#findComment-1085497 Share on other sites More sharing options...
jmclocals Posted July 13, 2010 Author Share Posted July 13, 2010 I thought i defined it in my global.inc file? <?php $host = ''; $user = ''; $pass = ''; $name = ''; $db = &new MySQL($host,$user,$pass,$name); ?> Do I need to redifine it in my functions.inc script as well? What should I do? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/207640-fatal-error-call-to-undefined-method-mysqlquery-in-homecontent366079136/#findComment-1085536 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.