RE: [PHP] help with ERROR!

From: Date: Wed, 21 May 2003 11:33:42 +0000
Subject: RE: [PHP] help with ERROR!
Groups: php.general 
Request: Send a blank email to php-general+get-148401@lists.php.net to get a copy of this message
[snip] I've already tried to help him with this privately. The odd part is that mysql_query is returning true, not a resource, even though it's a select query. >This is my Code >http://nopaste.php-q.net/15837 > > >This is My Error! >------------------- >Warning: mysql_result(): supplied argument is not a valid MySQL result >resource in /home/virtual/site12/fst/var/www/html/do_authuser.php on >line 27 result fetch failed [/snip] Line 27 is; $password_from_db = mysql_result( $query, 0 ) or die( "result fetch failed" ); The query is; $sql = "SELECT password FROM auth_users WHERE username = '$_POST[username]'"; First, the connection string to the database ( $query, 0 ). IHMO the connection to the DB should be contained in a variable rather than using the integer to access the connection. It's coding preference really, but most would consider it cleaner. Second, the query. Try this.... $sql = "SELECT password FROM auth_users WHERE username = '" . $_POST['username'] . "' "; ....where the variable for the username is concated into the query, and the array identifier is in single quotes. One thing you can do really quickly is to print the query to the screen as a test after you have formed it to see if it looks correct; $sql = "SELECT password FROM auth_users WHERE username = '$_POST[username]'"; print($sql . "\n"); Also, a more informative query failure info can be returned like this; $sql = "SELECT password FROM auth_users WHERE username = '" . $_POST['username'] . "' "; if(!($query = mysql_query($sql, 0))){ print("MySQL error: " . mysql_error() . "\n"); exit(); } HTH! Jay

« previous php.general (#148401) next »