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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.