Page 1 of 1

PHP Login: expects parameter 1 to be resource, boolean given

Posted: Mon Nov 28, 2011 11:59 am
by shaunthomson
Hi

I too am having the same problem. Records are being entered into the database, but I get the error:

Warning: mysql_result() expects parameter 1 to be resource, boolean given in /home/########/public_html/core/inc/user.inc.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /home//########//public_html/core/inc/user.inc.php:7) in /home//########//public_html/register.php on line 33

The user.inc.php code is:
<?php

function user_exists($user) {
	
	$user = mysql_real_escape_string($user);
	$total = mysql_query("SELECT_COUNT(`user_id`) FROM `########_users` WHERE `user_name` = '{$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}')");
	
}

?>
Is there something obvious I've missed here?

Thanks for your time and help.

Shaun

Re: PHP Login: expects parameter 1 to be resource, boolean g

Posted: Mon Nov 28, 2011 12:15 pm
by shaunthomson
Never mind. SELECT_COUNT should be SELECT COUNT without the underscore.

7 hours for a f^%@!$#^%@ underscore!!!!!!!!!!!!!!!!!!!!!!!!!

Onwards and upwards...

Re: PHP Login: expects parameter 1 to be resource, boolean g

Posted: Mon Nov 28, 2011 7:06 pm
by jacek
Well, you will hopefully never make the same mistake again :D

For future reference, adding
echo mysql_error();
after which every mysql_query() is failing is usually a good first step to finding the problem.