Jump to content

Checking Variable for existing entry.


crawlerbasher

Recommended Posts

$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

$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
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.