Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php class redeclaration problem
Old 03-22-2008, 10:04 AM php class redeclaration problem
andyp's Avatar
Extreme Talker

Posts: 165
Name: andy patterson
Trades: 0
whenever I go onto my page utilzing the sql class i get this error message:
Quote:
Fatal error: Cannot redeclare class sql in /includes/sql.php on line 8
this is what i have in my sql.php class
PHP Code:
    class sql
    
{
        function 
Connect()
        {
            require(
"aihsfijnud.php");//renamed for security
            
@mysql_connect($host$username$password);
            @
mysql_select_db($db);
        }
        function 
Close()
        {
            @
mysql_close();
        }
        function 
Query($sql)
        {
            
$this->Connect();
            
$query = @mysql_query($sql) or die("sorry no results matched your criteria");
            
$row = @mysql_fetch_array($query);
            
$this->Close();
            return 
$row;
        }
        function 
Login()
        {
            if(!isset(
$_SESSION['author']))
            {
            
$this->Connect();
            
$username md9($_POST['username']);
            
$password md9($_POST['password']);
            
$this->Query("select * from profiles where username='$username'");
            if( 
$row['password'] == $password )
            {
                
session_start();
                
$_SESSION['author'] = $row['name'];
                
header("location:".$_SERVER['HTTP_REFERER']);
            }
            else
            {
                echo(
"sorry your login details is incorrect");
            }
            
$this->Close();
            }
            else
            {
                echo(
"Your Are Logged In. Logout If You Wish");
            }
        }
        function 
Logout()
        {
            
session_destroy();
            unset(
$_SESSION['author']);
        }
            
    } 
I'm at my wits end with this one if you want to see the error for yourself its at http://ap-gfx.com/?show=profile
__________________
My webmaster news & tips blogs with free scripts and tutorials -
Please login or register to view this content. Registration is FREE
andyp is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-22-2008, 11:23 AM Re: php class redeclaration problem
mork29's Avatar
Extreme Talker

Posts: 242
Name: Keith Yelnick
Trades: 0
1) Is this a custom class that you've written? Have you tried taking a look at mysqli? It's an class based implementation of PHP's mySQL API. It's actually pretty well done.

2) Are you including this class from more than one place? Have you tried changing to include_once() instead of just include() ?

3) Is sql a reserved name? I'm not sure, but I wouldn't be surprised if this is an invalid name used already by PHP
mork29 is offline
Reply With Quote
View Public Profile
 
Old 03-22-2008, 01:50 PM Re: php class redeclaration problem
andyp's Avatar
Extreme Talker

Posts: 165
Name: andy patterson
Trades: 0
well i did try renaming the class but the same result came up.
__________________
My webmaster news & tips blogs with free scripts and tutorials -
Please login or register to view this content. Registration is FREE
andyp is offline
Reply With Quote
View Public Profile
 
Old 03-22-2008, 05:05 PM Re: php class redeclaration problem
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by andyp View Post
well i did try renaming the class but the same result came up.
That means that you are redeclaring the class. Try changing all of your requires and includes to require_once and include_once
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-22-2008, 06:15 PM Re: php class redeclaration problem
carloncho's Avatar
Skilled Talker

Posts: 80
Name: Carlos
Trades: 0
Yes, yu must to include the class one time. If you use a sentence like this:
Quote:
include('sql.class.php');
or
require('sql.class.php');
You must to test this:

Quote:
include_once('sql.class.php');
or
require_once('sql.class.php');
__________________
-----------------------

Please login or register to view this content. Registration is FREE
carloncho is offline
Reply With Quote
View Public Profile Visit carloncho's homepage!
 
Reply     « Reply to php class redeclaration problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.58915 seconds with 12 queries