![Wink ;)](./images/smilies/icon_e_wink.gif)
Im getting this error:
Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\user_system\core\inc\user.inc.php on line 7
Code:
user.inc.php
[syntax=php]<?php
// Checks if the given username exists in the database.
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;
}
// Checks is the given username and password combination is valid.
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;
}
// Adds a user to the database.
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}') ");
}
?>[/syntax]
register.php:
[syntax=php]<?php
include('core/init.inc.php');
if (isset($_POST['username'], $_POST['password'], $_POST['repeat_password']))
{
if (empty($_POST['username']))
{
$errors[] = 'The username cannot be empty.';
}
if (empty($_POST['password']) || empty($_POST['repeat_password']))
{
$errors[] = 'The password cannot be empty.';
}
if ($_POST['password'] !== $_POST['repeat_password'])
{
$errors[] = 'Password verfication failed.';
}
if (user_exists($_POST['username']))
{
$errors[] = 'The username you enetered is already taken.';
}
if (empty($errors) == false)
{
add_user($_POST['username'], $_POST['password']);
$_SESSION['username'] = htmlentities($_POST['username']);
header('Location: protected.php');
die();
}
}
?>[/syntax]
Any ideas? I tried a google, but my level of understanding is not great enough yet to work out what's going on.