I'm following the user account tutorials and I've been hit with this problem. I've read all the threads on this but nothing seems to help me. I'm not sure if it's something wrong with the coding or with my database.
This is the error I get when I click "register" in register.php without filling in the form. I noticed when he clicked it without filling it out, he got no error:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /hermes/bosweb26b/b2305/ipg.truecoloursdaycareca/qstdy/user.inc.php on line 7So this is my code for user.inc.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}') "); } ?>I'm getting the error for:
return (mysql_result($total, 0) == '1') ? true : false;What can I do to fix this?
Thank you.