lovephp Posted November 3, 2012 Share Posted November 3, 2012 guys how do i do this $id = $_REQUEST[''id']; $name = $_SESSION[''name']; if(Name Exist In Field == "Matching With Requested ID" ){ echo "show results"; }else{ echo "error"; } Quote Link to comment https://forums.phpfreaks.com/topic/270264-how-to-check-if-name-exist-in-the-sql-table-matching-with-id/ Share on other sites More sharing options...
berridgeab Posted November 3, 2012 Share Posted November 3, 2012 Do you wish to match the given data to a record in a database? Quote Link to comment https://forums.phpfreaks.com/topic/270264-how-to-check-if-name-exist-in-the-sql-table-matching-with-id/#findComment-1390024 Share on other sites More sharing options...
lovephp Posted November 3, 2012 Author Share Posted November 3, 2012 yes thats right from database i want to match whether the name exist in table field with the id requested Quote Link to comment https://forums.phpfreaks.com/topic/270264-how-to-check-if-name-exist-in-the-sql-table-matching-with-id/#findComment-1390031 Share on other sites More sharing options...
Pikachu2000 Posted November 3, 2012 Share Posted November 3, 2012 $query = "SELECT COUNT(1) FROM table WHERE id = $id AND name = '$name'"; if( $result = mysql_query($query) ) { $array = mysql_fetch_row($result); if( $array[0] === 1 ) { // name and id exist } else { // name and id don't exist } } else { // query resulted in an error } Quote Link to comment https://forums.phpfreaks.com/topic/270264-how-to-check-if-name-exist-in-the-sql-table-matching-with-id/#findComment-1390033 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.