WhiteCube Posted December 10, 2007 Share Posted December 10, 2007 hi! I have this code $result = mysql_query("SELECT * FROM rpg_user WHERE username = '$username'") or die(mysql_error()); which finds the row in my table which matches my $username variable.. However.. sometimes.. it's not there.. What code can i use to tell me so? something like if($username does not exist in row){ echo "does not exist" }else{ echo "does exist" } can someone write up a simple script for me? Thanks! Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 you can use mysql_num_rows function for that below is an example $result = mysql_query("SELECT * FROM rpg_user WHERE username = '$username'") or die(mysql_error()); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { echo "exists"; } else { echo "does not exists"'; } hope its helpful Quote Link to comment Share on other sites More sharing options...
WhiteCube Posted December 11, 2007 Author Share Posted December 11, 2007 Great stuff!! lol Your helping me out a lot!! lol Quote Link to comment 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.