crawlerbasher Posted May 15, 2010 Share Posted May 15, 2010 $email = strip_tags($_GET['e']); if (is_numeric ($email)) { echo "True"; } else { echo "False"; } This is a peace of code that I'm working with. Now I know how to connect to database and that. But the one thing that I've no idea on how to do is this. Checking the number stored in the Variable and comparing that with the id stored in the database. An example. $email = 1 Database has an id that contains 1 $email = 43 Database has an id that contains 43 $email = 54 Database has no id that contains 54 and so the script is not executed. Link to comment https://forums.phpfreaks.com/topic/201862-checking-variable-for-existing-entry/ Share on other sites More sharing options...
Pikachu2000 Posted May 15, 2010 Share Posted May 15, 2010 $query = "SELECT db_field FROM db_table WHERE db_field = $email LIMIT 1"; $result = mysql_query( $query ); $num = mysql_num_rows($result) if( $num > 0 ) { // Record exists, so do something } else { // Record doesn't exist, so do something else } Link to comment https://forums.phpfreaks.com/topic/201862-checking-variable-for-existing-entry/#findComment-1058776 Share on other sites More sharing options...
crawlerbasher Posted May 15, 2010 Author Share Posted May 15, 2010 Thank you. I was looking at something like this to find if the variable existed or not. But was not working. But your code was shorter and cleaner and worked. Thank you. Link to comment https://forums.phpfreaks.com/topic/201862-checking-variable-for-existing-entry/#findComment-1058784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.