PURU Posted July 30, 2008 Share Posted July 30, 2008 hey I HAVE BEEN USING PHP DEV 5.I want to verify username and password with database using function mysql_num_rows but every time i use this function it show s error.So can you help me out.My code is given below. $name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist > 0){ echo "I'm sorry but the username you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); } Link to comment https://forums.phpfreaks.com/topic/117387-problem-in-using-function-mysql_num_rows/ Share on other sites More sharing options...
DarkWater Posted July 30, 2008 Share Posted July 30, 2008 You have no $ in front of checkuser. Also, what error does it show? Link to comment https://forums.phpfreaks.com/topic/117387-problem-in-using-function-mysql_num_rows/#findComment-603819 Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); should be $checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); Link to comment https://forums.phpfreaks.com/topic/117387-problem-in-using-function-mysql_num_rows/#findComment-603820 Share on other sites More sharing options...
PURU Posted July 30, 2008 Author Share Posted July 30, 2008 I have $ in fron of checker still it is showing error :it says function mysql_num_rows is not valid for mysql Link to comment https://forums.phpfreaks.com/topic/117387-problem-in-using-function-mysql_num_rows/#findComment-603858 Share on other sites More sharing options...
chacha102 Posted July 30, 2008 Share Posted July 30, 2008 Are you testing this with a valid user name? Link to comment https://forums.phpfreaks.com/topic/117387-problem-in-using-function-mysql_num_rows/#findComment-603861 Share on other sites More sharing options...
chacha102 Posted July 30, 2008 Share Posted July 30, 2008 You might also want to use (to clean your data) a sprintf() to insert the user name. Link to comment https://forums.phpfreaks.com/topic/117387-problem-in-using-function-mysql_num_rows/#findComment-603866 Share on other sites More sharing options...
rhodesa Posted July 30, 2008 Share Posted July 30, 2008 please use the following code and copy/paste the EXACT error displayed: <?php $name = mysql_real_escape_string($_POST['name']); $email = mysql_real_escape_string($_POST['email']); $username = mysql_real_escape_string($_POST['username']); $password = md5($_POST['password']); $checkuser = mysql_query("SELECT username FROM users WHERE username='$username'") or die(mysql_error()); $username_exist = mysql_num_rows($checkuser); if($username_exist > 0){ echo "I'm sorry but the username you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); } ?> Link to comment https://forums.phpfreaks.com/topic/117387-problem-in-using-function-mysql_num_rows/#findComment-603868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.