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
Call to a member function fetch_assoc() on a non-object
Old 08-24-2011, 04:28 PM Call to a member function fetch_assoc() on a non-object
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Hi Guys,

Bit of a problem on a page i'm trying to code. I am trying to get the code able to pull out rows of information from the database by using

while()....

Below is the code that i have, and as the title says; this is the error that i'm getting.

Code:
$mySQL = new mod_db();
$mySQL->connection();

$sql = "SELECT * FROM table WHERE userName = '$userName' AND password = '$password'";

if(!$mySQL->query($sql)) {
	echo "Unable to check data from table";
}
if($mySQL->nums($sql,'') == "0") {
	echo "<script>alert('Username / Password Incorrect');</script>"; // English Error Message   
	echo "<meta HTTP-EQUIV='REFRESH' content='0; url=http://www.website.co.uk/admin/'>";
             
} else {

    $result = $mySQL->query($sql);	
    while($row = $result->fetch_assoc())
    {
		$userID = $row['userID'];
		echo $userID;
	}
Thanks
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-25-2011, 02:12 AM Re: Call to a member function fetch_assoc() on a non-object
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
I cannot see the error.
If you pasted well, you have a mising '}' at the end.
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 08-25-2011, 02:25 AM Re: Call to a member function fetch_assoc() on a non-object
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
$result is not an object, which most likely means your query failed.

There are a couple of issues with your overall design as well. For one you are executing the query twice. Here:
PHP Code:
if(!$mySQL->query($sql)) 
and here:
PHP Code:
$result $mySQL->query($sql); 
The other issues I see is here:
PHP Code:
if($mySQL->nums($sql,'') == "0"
I have no idea what library you're using, but it seems like if you want to get the number of rows you would get it from a result resource, not a query string. Also, why are you quoting the zero? Technically it will still work, but it is poor coding.

Quote:
Originally Posted by vectorialpx View Post
If you pasted well, you have a mising '}' at the end.
If there were an issue with his syntax he would get a parse error.
__________________

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

Last edited by NullPointer; 08-25-2011 at 02:29 AM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-25-2011, 03:11 AM Re: Call to a member function fetch_assoc() on a non-object
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
Quote:
Originally Posted by NullPointer View Post
If there were an issue with his syntax he would get a parse error.
Like I said, I cannot see the error. I don't know if you see more than me but after the "this is the error that i'm getting" I can only see the code.
Anyway... it's good that you figure it out.
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 08-25-2011, 03:33 AM Re: Call to a member function fetch_assoc() on a non-object
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The error message is in the title of the post:
Quote:
Call to a member function fetch_assoc() on a non-object
If there were a syntax error he would be getting a parse error before the code was even evaluated. So the fact that he is getting that message instead means his syntax is fine.
__________________

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 offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-26-2011, 01:48 PM Re: Call to a member function fetch_assoc() on a non-object
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Thank you for the replies guys, I fixed it in the end.. Also thank you for the pointers in the coding, bits i need to iron out
feraira is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Call to a member function fetch_assoc() on a non-object
 

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.49995 seconds with 12 queries