Page 1 of 1

not a valid MySQL result resource

Posted: Fri Apr 06, 2012 3:18 pm
by Mychaelvelli
Hello All,

I am getting the following errors and I cannot figure it out:

Warning: mysql_result() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/login/core/inc/user.inc.php on line 11

Here is the code:
<?php

function user_exists($user){

	$user = mysql_real_escape_string($user);
	
	$total = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'user_name' = '{$user}'");
	
	//why is this not allowing the script to register the user???
	return (mysql_result($total, 0) == '1') ? true : false;
}

function valid_credentials($user, $pass){
	$user = mysql_real_escape_string($user);
	$pass = sha1($pass);
	
	$total = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'user_name' = '{$user}' AND 'user_password' = '{$pass}'");
	
	return (mysql_result($total, 0) == '1') ? true : false;
}

function add_user($user, $pass){
	$user = mysql_real_escape_string(htmlentities($user));
	$pass = sha1($pass);
	
	mysql_query("INSERT INTO 'users' ('user_name', 'user_password') VALUES ('{$user}', '{$pass}')");
}

?>
I am new to PHP, it's only been a few weeks. I followed the video (i thought) to a "T" but i guess not... can anyone lend a hand and tell me what I did wrong? Thanks...

Re: not a valid MySQL result resource

Posted: Fri Apr 06, 2012 3:21 pm
by SkillBuzz
try again using the:
[syntax=php]
[/syntax] thingies, but it also looks like you are using the wrong quote marks..

Re: not a valid MySQL result resource

Posted: Fri Apr 06, 2012 11:05 pm
by SkillBuzz
i meant do this:
<?php

function user_exists($user){

$user = mysql_real_escape_string($user);

$total = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'user_name' = '{$user}'");

//why is this not allowing the script to register the user???
return (mysql_result($total, 0) == '1') ? true : false;
}

function valid_credentials($user, $pass){
$user = mysql_real_escape_string($user);
$pass = sha1($pass);

$total = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'user_name' = '{$user}' AND 'user_password' = '{$pass}'");

return (mysql_result($total, 0) == '1') ? true : false;
}

function add_user($user, $pass){
$user = mysql_real_escape_string(htmlentities($user));
$pass = sha1($pass);

mysql_query("INSERT INTO 'users' ('user_name', 'user_password') VALUES ('{$user}', '{$pass}')");
}

?>
And use ` instead of ' quotes

Re: not a valid MySQL result resource

Posted: Fri Apr 06, 2012 11:43 pm
by jacek
Yep that is it If you use ' it tells MySQL that the thing between them is not a table name, to tell it that is is a table of column name you need to use backticks `

Re: not a valid MySQL result resource

Posted: Sun Apr 08, 2012 12:53 am
by Mychaelvelli
oooooh ok, that makes sense. I will give it a try and let you know... Thanks guys.