heldenbrau Posted August 12, 2009 Share Posted August 12, 2009 $mysqli = new mysqli("localhost", "username", "password", "user"); if ($mysqli === false) { die("ERROR: Could not connect to database. " . mysqli_connect_error()); } $defun=$mysqli->escape_string($defendant); $sql="SELECT email FROM users WHERE username='$defun'"; if ($result = $msyqli->query($sql)) { $row = $result->fetch_assoc(); $mail = $row['email']; }else{ die("No user could be found with that username"); } I always get info from the database with this method. But in this one bit of the program on one php file, I get the error: Fatal error: Call to a member function query() on a non-object The line it has a problem with is if ($result = $msyqli->query($sql)) { What does the error actually mean, and what would cause it to happen? Link to comment https://forums.phpfreaks.com/topic/169962-solved-why-is-this-not-working-call-to-a-member-function-query-on-a-non-object/ Share on other sites More sharing options...
roopurt18 Posted August 12, 2009 Share Posted August 12, 2009 It means exactly what it says. You're calling a member function, query, on an object, $mysqli. Except the object is not an object (the error message says non-object) so it has no member functions and the code crashes. I suggest adding a var_dump( $mysqli ) right before the bad line; then you'll see what type of variable $mysqli really is. Link to comment https://forums.phpfreaks.com/topic/169962-solved-why-is-this-not-working-call-to-a-member-function-query-on-a-non-object/#findComment-896713 Share on other sites More sharing options...
heldenbrau Posted August 12, 2009 Author Share Posted August 12, 2009 It says NULL. I have been working on this problem all night and have found a solution, but I don't understand fuly what is going on. If I close $mysql after each query and then start a new $mysql and log in again, then it works, even though it is the same database I am using. Do I have to do this every time I want to start a new query? Link to comment https://forums.phpfreaks.com/topic/169962-solved-why-is-this-not-working-call-to-a-member-function-query-on-a-non-object/#findComment-896730 Share on other sites More sharing options...
play_ Posted August 12, 2009 Share Posted August 12, 2009 You misspelled it. $mysqli = new mysqli("localhost", "username", "password", "user"); if ($result = $msyqli->query($sql)) { one says mysqli, the other says my msyqli Link to comment https://forums.phpfreaks.com/topic/169962-solved-why-is-this-not-working-call-to-a-member-function-query-on-a-non-object/#findComment-896734 Share on other sites More sharing options...
roopurt18 Posted August 12, 2009 Share Posted August 12, 2009 Haha. I swear I looked for that but I guess my poor brain managed to transpose the letters anyways. Link to comment https://forums.phpfreaks.com/topic/169962-solved-why-is-this-not-working-call-to-a-member-function-query-on-a-non-object/#findComment-896746 Share on other sites More sharing options...
heldenbrau Posted August 12, 2009 Author Share Posted August 12, 2009 omg. Thanks for pointing that out Link to comment https://forums.phpfreaks.com/topic/169962-solved-why-is-this-not-working-call-to-a-member-function-query-on-a-non-object/#findComment-896789 Share on other sites More sharing options...
play_ Posted August 12, 2009 Share Posted August 12, 2009 =] Link to comment https://forums.phpfreaks.com/topic/169962-solved-why-is-this-not-working-call-to-a-member-function-query-on-a-non-object/#findComment-896820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.