Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Fatal error

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Fatal error

    Fatal error: Call to a member function on a non-object

    All this is from a php book i been reading. I guess the error is to do with this bit on line 17

    $result = $db_conn->query($query);
    if ($result->num_rows >0 )

    Am guessing i have to define the object or something? this what the book tells me to do code for code i don't understand why it don't work?
    Last edited by Lyconpire; 04-27-2006 at 01:13 PM.

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,859
    Thanks
    22
    Thanked 157 Times in 148 Posts
    I suggest you read this article : http://www.phpfreaks.com/tutorials/48/0.php

    on how to write and use PHP classes.

    At some point you need to include the class and intialize it (before you use the class):

    PHP Code:
    include "MyClass.class.php";

    $myclass = &New MyClass
    Then you can accesss the methods/properties inside the class using $myclass:

    PHP Code:
    $myclass->method(); 
    or
    PHP Code:
    $myclass->property "whatever"
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #3
    Registered User
    Join Date
    Jul 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol what... ok erm i will read that thanks ;-)

    is there a fix for my code that i summited or it to far gone to fix?
    Last edited by Lyconpire; 04-26-2006 at 11:09 PM.

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    yes you should get a new book as the error in there is quite dumb (unless it's not the full code).
    mysql_connect() doesn't return an object.
    The closest thing I'd to it would be the use of the mysqli extension which is object oriented.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #5
    Registered User
    Join Date
    Jul 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marek_mar
    yes you should get a new book as the error in there is quite dumb (unless it's not the full code).
    mysql_connect() doesn't return an object.
    The closest thing I'd to it would be the use of the mysqli extension which is object oriented.
    right i understand that ok i tried mysqli and got this error now.

    Fatal error: Call to undefined function: mysqli() in auth.php on line 10

    $db_conn = mysqli
    ('localhost', '******', '******', '******');


    Running MySQL version 4.0.25-standard

    i just seem to be albe to bring the errors out of php....
    Last edited by Lyconpire; 04-26-2006 at 11:32 PM.

  • #6
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Objects are created with the new keyword, try $db_host = new mysqli('stuff');

  • #7
    Registered User
    Join Date
    Jul 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeh hehe i seen that in google guess what i now get this...

    Fatal error: Cannot instantiate non-existent class: mysqli in auth.php on line 10


    $db_conn = new mysqli
    ('localhost', '******', '******', '*****');

  • #8
    Registered User
    Join Date
    Jul 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Lyconpire
    yeh hehe i seen that in google guess what i now get this...

    Fatal error: Cannot instantiate non-existent class: mysqli in auth.php on line 10


    $db_conn = new mysqli
    ('localhost', '******', '******', '*****');

    ooo google says i need php5 i will call my host tomorrow

  • #9
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by ralph l mayo
    Objects are created with the new keyword, try $db_host = new mysqli('stuff');
    That keyword is called an operator
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •