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

Post here is you are having problems with any of the tutorials.
Post Reply
shaunthomson
Posts: 19
Joined: Mon Nov 28, 2011 11:53 am

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

Post 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
shaunthomson
Posts: 19
Joined: Mon Nov 28, 2011 11:53 am

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

Post by shaunthomson »

Never mind. SELECT_COUNT should be SELECT COUNT without the underscore.

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

Onwards and upwards...
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post 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.
Image
Post Reply