user3403027
user3403027

Reputation: 7

Get url id in php and check whether it exist or not in database

I have written code in php in order to get id from url and check whether it exists or not in mysql database. I have an existing value in the database but still getting a problem saying value is not found. Please anyone have a solution?

Here is my code:

<?php
      require 'Common.php';
      $Email=$_GET['id'];
      $result = mysql_query("SELECT email FROM cdcol.employees WHERE email='$Email'");
      if(mysql_num_rows($result) >0)

        {
            echo 'Email Found'; 
        }
    else
        {
        echo 'Email NOT Found';
        }
?>

Upvotes: 1

Views: 1119

Answers (1)

makallio85
makallio85

Reputation: 1356

Typo:

$result = mysql_query("SELECT email FROM cdcol.employees WHERE email='"mysql_real_escape_string($Email)"');

=>

$result = mysql_query("SELECT email FROM cdcol.employees WHERE email='".mysql_real_escape_string($Email)."'");

To improve the performance of this query, use LIMIT 1 (you check if there is more than 0 lines):

$result = mysql_query("SELECT email FROM cdcol.employees WHERE email='".mysql_real_escape_string($Email)."' LIMIT 1");

Upvotes: 3

Related Questions