oliveralden Posted July 4, 2006 Share Posted July 4, 2006 Hi there. I'm fairly new to PHP, and am trying to integrate a shopping cart code with my template. I seem to have a header problem which I can't quite solve.Here's the error:Fatal error: Cannot instantiate non-existent class: mysql in /home/weirdore/public_html/cartjune/cart-demo/inc/global.inc.php on line 6And here's the code, up to the end of the header & title:-----------------------------------------------------------------------------------------------------<?phpsession_start();require_once('http://www.weirdorecords.com/cartjune/functions.inc.php');require_once('http://www.weirdorecords.com/cartjune/global.inc.php');require_once('http://www.weirdorecords.com/cartjune/mysql.class.php');$cart = $_SESSION['cart'];$action = $_GET['action'];switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break;}$_SESSION['cart'] = $cart;?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><!-- InstanceBegin template="/Templates/frontpage.dwt" codeOutsideHTMLIsLocked="false" --><head><meta name="description" content="Weirdo records sells experimental recordings on lp, cd, cdr, & cassette. We love noise kids, psychedelic freaks, retards banging on kitchen pots, ultra-snobby longhairs & many other types of record collecting nerds."><meta name="keywords" content="weirdo records werido weird noise cd lp cds lps rock psychedelic avant garde wolf eyes lightning bolt improv experimental volcanic forced music sounds recordings"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><!-- InstanceBeginEditable name="doctitle" --><title>Welcome to Weirdo Records</title>------------------------------------------------------------------------------------------------------I'm using Dreamweaver & Windows xp, & a webhosting server. The code does work without the template, but whenever I try to patch them together I've run into this problem. Any suggestions would be greatly appreciated. Thanks for your time.-Oliver Alden Link to comment https://forums.phpfreaks.com/topic/13677-cannot-instantiate-non-existent-class/ Share on other sites More sharing options...
trq Posted July 4, 2006 Share Posted July 4, 2006 Um... the error says your trying to use the mysql class from with global.inc.php. You actually don't include your mysql.class.php file untill after your global.inc.php file, make sense? Link to comment https://forums.phpfreaks.com/topic/13677-cannot-instantiate-non-existent-class/#findComment-53068 Share on other sites More sharing options...
oliveralden Posted July 4, 2006 Author Share Posted July 4, 2006 Well, I *think* I understand what you're saying. However, it doesn't seem to matter what order I use for those 3 include files, I still get the same error message. The global.inc.php, by the way, just uses $ to define host, user, pass, dbname. So I don't think the error is within that file. Any other ideas from anyone? Thanks. Link to comment https://forums.phpfreaks.com/topic/13677-cannot-instantiate-non-existent-class/#findComment-53072 Share on other sites More sharing options...
trq Posted July 4, 2006 Share Posted July 4, 2006 can we see global.inc.php? Link to comment https://forums.phpfreaks.com/topic/13677-cannot-instantiate-non-existent-class/#findComment-53075 Share on other sites More sharing options...
oliveralden Posted July 4, 2006 Author Share Posted July 4, 2006 But of course. In the interim, I realized that it must be where the problem is after all:<?php$host = 'localhost';$user = 'weirdore';$pass = 'smitty';$name = 'weirdore_catalog';$db = &new MySQL($host,$user,$pass,$name);?>Thanks. Link to comment https://forums.phpfreaks.com/topic/13677-cannot-instantiate-non-existent-class/#findComment-53076 Share on other sites More sharing options...
trq Posted July 4, 2006 Share Posted July 4, 2006 This line...[code=php:0]$db = &new MySQL($host,$user,$pass,$name);[/code]is where you are trying to instantiate the class MySQL, which I can only assume is defined within mysql.class.php. You need to include mysql.class.php before global.inc.php. Link to comment https://forums.phpfreaks.com/topic/13677-cannot-instantiate-non-existent-class/#findComment-53078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.