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... Link to comment https://forums.phpfreaks.com/topic/60159-how-do-i-check-if-a-value-is-already-in-a-mysql-table/ 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 ?> Link to comment https://forums.phpfreaks.com/topic/60159-how-do-i-check-if-a-value-is-already-in-a-mysql-table/#findComment-299279 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 } Link to comment https://forums.phpfreaks.com/topic/60159-how-do-i-check-if-a-value-is-already-in-a-mysql-table/#findComment-299318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.