我已经在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';
}
?>
答案 0 :(得分:3)
错字:
$result = mysql_query("SELECT email FROM cdcol.employees WHERE email='"mysql_real_escape_string($Email)"');
=&GT;
$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");