1

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';
        }
?>

1 Answers1

3

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");
Martijn
  • 15,791
  • 4
  • 36
  • 68
makallio85
  • 1,366
  • 2
  • 14
  • 29
  • Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\phpMyAdmin\mysql_ajax\url_check_email_blacklist.php on line 6 ......this is the error i ma getting – user3403027 Mar 23 '14 at 15:58
  • could you please post result of this: echo "SELECT email FROM cdcol.employees WHERE email='".mysql_real_escape_string($Email)."'"; – makallio85 Mar 23 '14 at 16:00
  • @AngularAddict, You still have a typo in the query ! You need to add a **double quote** at the end. – Shankar Narayana Damodaran Mar 23 '14 at 16:01
  • Hi i make changes in the code and i dont want mysql_real_string but its giving me the error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\phpMyAdmin\mysql_ajax\url_check_email_blacklist.php on line 6 – user3403027 Mar 23 '14 at 16:03
  • Your query has an error and returns false (=boolean). Add `or die(mysql_error()); after the query to see the error – Martijn Mar 23 '14 at 16:05
  • I made that changes still giving the same error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\phpMyAdmin\mysql_ajax\url_check_email_blacklist.php on line 6 ...I am using php 5.3 is that a problem of using mysql_num_rows ? – user3403027 Mar 23 '14 at 16:06
  • I am running the same query and its properly running in mysql database – user3403027 Mar 23 '14 at 16:07