Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Supplied argument is not a valid MySQL result resource"

Status
Not open for further replies.

jwoods7

Technical User
Feb 19, 2003
36
US
I'm trying to create a function that I can use to pull information from a field in a database.

So far I'm in the testing stage...here's what I have...

function getMemberInfo($login, $field) {
$query="SELECT $field FROM users WHERE login='$login'";
while($row = mysql_fetch_array($query)){
// get information from field:
return $row['$field'];
}
//Didn't find info:
return "empty";
}


The function is called like this:
print(getMemberInfo($_SESSION['login'], 'firstname'));
Where session is a unique login id for each member. This would print the first name of the member that is logged in under the current session ID on the computer.

Why do I get a
Warning: Supplied argument is not a valid MySQL result resource
ERROR AND WHAT DOES THAT MEAN???
Any other ways to do this? (simple please, 4th day learning PHP!!)

Thanks in advance
 
Hi!

Why do I get a
Warning: Supplied argument is not a valid MySQL result resource
ERROR AND WHAT DOES THAT MEAN???


1. When you send your SQL query you expect a result. The result is provided as a 'resource'. When there are no rows or the SQL statement fails for some reason there is no result. Trying to retreive rows from such a query produces the error.

What else?
2. You actually never sent the query to the database server, all you did is assign it to a variable called query.
To get a result identifier you need to use mysql_query($query); Also check if the SQL fails or not:
Code:
$SQL = "SELECT $field FROM mytable WHERE mycolumn='$myvar'";
$result = mysql_query($sql) OR DIE(mysql_error()); # prints error if fail
# for fun look how many rows were returned
echo(mysql_num_rows($result)." were found");

Good luck in the PHP world!

 
Thanks!


Why am I getting "Query was Empty" as a result from this function? The values are set in the database, I can verify that...I'm trying to get a firstname of a member

CALLED FROM:
getMemberInfo('3','firstname')
{verified "firstname" is exactly as in table, login #3 has firstname value....}

function getMemberInfo($login, $field) {
$query="SELECT * FROM users WHERE login = '$login'";
$result = mysql_query($sql) OR DIE(mysql_error());
echo(mysql_num_rows($result)." were found");
while($row = mysql_fetch_array($result)){

return $row['$field'];
}
}
 
oh geez I'm retarded. Should be "checking the inline specs on the girders" like Tommy Boy.
(quote from movie Tommy Boy)


Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top