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! Quote 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) { //... } Quote 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. } Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.