Winston_Smith Posted August 16, 2008 Share Posted August 16, 2008 Ok I'm trying to check 2 rows in my DB, fname and lname. I want to check and see if the full name is in the DB and if so skip adding it. I'm very new at this, been playing with this for a while now. Now that I think about it it could match a first name from one row with a last name from another the way I was trying. This is what I've been working with, horrible I know. $namechecker = mysql_query("SELECT * FROM ecfiber WHERE fname='$fname'") or die(mysql_error()); $namechecker2 = mysql_query("SELECT * FROM ecfiber WHERE lname='$lname'") or die(mysql_error()); $check = $namechecker.$namechecker2; if ($check == false){ Link to comment https://forums.phpfreaks.com/topic/119938-check-2-rows-in-db/ Share on other sites More sharing options...
revraz Posted August 16, 2008 Share Posted August 16, 2008 You can use AND in your query SELECT * FROM ecfiber WHERE fname = '$fname' AND lname = '$lname' Link to comment https://forums.phpfreaks.com/topic/119938-check-2-rows-in-db/#findComment-617867 Share on other sites More sharing options...
Winston_Smith Posted August 16, 2008 Author Share Posted August 16, 2008 You can use AND in your query SELECT * FROM ecfiber WHERE fname = '$fname' AND lname = '$lname' Thank you, how would I check that they both are in the same row? Link to comment https://forums.phpfreaks.com/topic/119938-check-2-rows-in-db/#findComment-617869 Share on other sites More sharing options...
marcus Posted August 16, 2008 Share Posted August 16, 2008 <?php $sql = "SELECT * FROM `ecfiber` WHERE `fname`='".$fname."' AND `lname`='".$lname."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) > 0){ // match found }else { // no match found } ?> Link to comment https://forums.phpfreaks.com/topic/119938-check-2-rows-in-db/#findComment-617872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.