Jump to content


Photo

Cannot instantiate non-existent class


  • Please log in to reply
5 replies to this topic

#1 oliveralden

oliveralden
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 04 July 2006 - 10:52 PM

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 6

And here's the code, up to the end of the header & title:
-----------------------------------------------------------------------------------------------------
<?php
session_start();
require_once('http://www.weirdorec...nctions.inc.php');
require_once('http://www.weirdorec.../global.inc.php');
require_once('http://www.weirdorec...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...l1-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

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 July 2006 - 11:13 PM

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?

#3 oliveralden

oliveralden
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 04 July 2006 - 11:21 PM

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.

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 July 2006 - 11:24 PM

can we see global.inc.php?

#5 oliveralden

oliveralden
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 04 July 2006 - 11:28 PM

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.

#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 July 2006 - 11:35 PM

This line...
$db = &new MySQL($host,$user,$pass,$name);
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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users