omar-do Posted August 10, 2011 Share Posted August 10, 2011 $checkuser = mysql_query("SELECT id FROM $tbl WHERE username = ".$_POST['username']." LIMIT 1 "); if ($checkuser){ $row = mysql_num_rows($checkuser); print 'username exist.'; } what's wrong ? when i click submit an username that is in the database its doesn't print 'username exist.' and the username goes in the database ... Quote Link to comment https://forums.phpfreaks.com/topic/244382-check-if-username-exist-in-datebase/ Share on other sites More sharing options...
$php_mysql$ Posted August 10, 2011 Share Posted August 10, 2011 $checkuser = mysql_query("SELECT id FROM $tbl WHERE username = ".$_POST['username']." LIMIT 1 "); if ($checkuser){ $row = mysql_num_rows($checkuser); print 'username exist.'; } should it be something like this ? $checkuser = mysql_query("SELECT id FROM $tbl WHERE username = ".$_POST['username']." LIMIT 1 "); if (!empty($checkuser)){ $row = mysql_num_rows($checkuser); print 'username exist.'; }else{ print 'username dont exist.'; } OR if ($checkuser !== ""){ $row = mysql_num_rows($checkuser); print 'username exist.'; }else{ print 'username dont exist.'; } what's wrong ? when i click submit an username that is in the database its doesn't print 'username exist.' and the username goes in the database ... Quote Link to comment https://forums.phpfreaks.com/topic/244382-check-if-username-exist-in-datebase/#findComment-1255169 Share on other sites More sharing options...
voip03 Posted August 10, 2011 Share Posted August 10, 2011 <? $checkuser = mysql_query("SELECT id FROM $tbl WHERE username = '".$_POST['username']."' LIMIT 1 "); $row = mysql_num_rows($checkuser); if ($row!=0) { print 'username exist.'; } else { print 'username dont exist.'; } ?> Number of result is equal is zero. Print username don’t exist Quote Link to comment https://forums.phpfreaks.com/topic/244382-check-if-username-exist-in-datebase/#findComment-1255171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.