1

我已经在 php 中编写了代码,以便从 url 获取 id 并检查它是否存在于 mysql 数据库中。我在数据库中有一个现有值,但仍然遇到问题,说找不到值。请问有人有解决办法吗?

这是我的代码:

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

1 回答 1

3

错字:

$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)."'");

要提高此查询的性能,请使用LIMIT 1(检查是否超过 0 行):

$result = mysql_query("SELECT email FROM cdcol.employees WHERE email='".mysql_real_escape_string($Email)."' LIMIT 1");
于 2014-03-23T15:57:07.507 回答