jd2007 Posted July 16, 2007 Share Posted July 16, 2007 How do i check if a value is already in a mysql table ? for e.g. if a username exists in a mysql table... Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 This is good for login scripts too <?php $q = "select `id` from table where Username = '$username'"; $result = mysql_query($q) or die(mysql_error()); $rCount = mysql_num_rows($result); if($rCount >0){ //There is an entry for it } else{ //There is not an entry for it ?> Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted July 16, 2007 Share Posted July 16, 2007 <?php $q = "select `id` from table where Username = '$username'"; $result = mysql_query($q) or die(mysql_error()); $rCount = mysql_num_rows($result); if($rCount >0){ //There is an entry for it } else{ //There is not an entry for it } ?> This is one idea.The another idea also works: if($result) { //for presence of data } else { //for absence of data } 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.