Jump to content

Archived

This topic is now archived and is closed to further replies.

oliveralden

Cannot instantiate non-existent class

Recommended Posts

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.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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
can we see global.inc.php?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.