jeff5656 Posted September 9, 2009 Share Posted September 9, 2009 Hello. I want to check to see if a record matches based on a field. So I have this: include "connectdb.php"; $consultsq2 = "SELECT * FROM members WHERE username= '" . $_POST['myusername'] . "'"; $result2 = mysql_query ($consultsq2) or die ("Invalid query: " . mysql_error ()); $row2 = mysql_fetch_array ($result2); What code do I write to see if it exists? Such as "if there is such a record, do this..." Thanks! Link to comment https://forums.phpfreaks.com/topic/173693-check-if-a-record-matches/ Share on other sites More sharing options...
Adam Posted September 9, 2009 Share Posted September 9, 2009 if (mysql_num_rows($result2) > 0) { //... } Link to comment https://forums.phpfreaks.com/topic/173693-check-if-a-record-matches/#findComment-915600 Share on other sites More sharing options...
RussellReal Posted September 9, 2009 Share Posted September 9, 2009 you could also do this.. if ($row = mysql_fetch_assoc($result2)) { // if it exists.. then $row holds the data for the row. } Link to comment https://forums.phpfreaks.com/topic/173693-check-if-a-record-matches/#findComment-915601 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.