Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php检查值是否在sql数据库中_Php_Sql_Registration - Fatal编程技术网

php检查值是否在sql数据库中

php检查值是否在sql数据库中,php,sql,registration,Php,Sql,Registration,可能重复: 看起来您可能忘记了连接到数据库,或者数据库中的详细信息可能不正确。当您遇到查询错误时,最好进行某种调试 通过结束查询die(mysql\u error())作为错误处理方法,如下所示: mysql\u查询(“选择来自客户的电子邮件,其中Email='$RegCusEmail')或die(mysql\u error()) 得到一个正确的错误 如果您使用的是5.2或更高版本,那么 function checkEmail( $EmailCheck ){ return filte

可能重复:


看起来您可能忘记了连接到数据库,或者数据库中的详细信息可能不正确。当您遇到查询错误时,最好进行某种调试 通过结束查询
die(mysql\u error())
作为错误处理方法,如下所示:

mysql\u查询(“选择来自客户的电子邮件,其中Email='$RegCusEmail')或die(mysql\u error())


得到一个正确的错误

如果您使用的是5.2或更高版本,那么

 function checkEmail( $EmailCheck ){
    return filter_var( $EmailCheck, FILTER_VALIDATE_EMAIL );
  }

添加错误处理。

改为根据结果执行此检查:

if ( ! is_resource( $EmailCheck ) || mysql_num_rows( $EmailCheck ) != 0 )
但是检查一下mysql\u error()
,您的查询可能有错误

1)使用PDO:

2) 验证电子邮件地址和电子邮件服务器

function isValidEmail ($email)
{
    if ($isemail=filter_var($email, FILTER_VALIDATE_EMAIL))
    {
        if(list($email,$domain) = explode('@',$email))
        {
            if(!getmxrr ($domain,$mxhosts)) 
            { 
                return FALSE; 
            }
            else 
            { 
                return TRUE; 
            }
        }
        else
        {
            return FALSE;
        }
    }
    else
    { 
    return FALSE; 
    } 

}

就像这个网站上的6个kazjillion其他问答一样,有着完全相同的错误信息:你的查询失败了,你盲目地认为它们成功了,现在它们失败了,你没有错误处理来清理混乱。请不要使用
mysql.*
函数来编写新代码。它们不再得到维护,社区已经开始。看到了吗?相反,你应该了解并使用or。我在phpmyadmin中检查了查询,它起作用了。这是测试它们是否起作用的有效方法吗?如果是,我需要修复它们吗?@user1990909你连接到数据库了吗?我看不到您在哪里连接和/或选择了正确的数据库。我知道这可能只是一个片段,所以您可能在这里忽略了它,但我只是检查您是否确实在实际代码中连接到了数据库。感谢您之前对其进行了注释并将其忘记。@user1990909您是否使用
mysql\u error()
检查查询?
if ( ! is_resource( $EmailCheck ) || mysql_num_rows( $EmailCheck ) != 0 )
//connection
$host =     "localhost";
$user =     "someuser";
$pass =     "somepass";
$database = "db_name";

$db = new PDO("mysql:host=$host;dbname=$database", $user, $pass,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")) or die("Connection error!");

$query = 'SELECT Customer.Email FROM Customer WHERE Customer.Email = :RegCusEmail';
$params = array(':RegCusEmail' => $RegCusEmail);

$result = db_query($query,$params);

if($result == false)
{
  //do stuff..
}


function db_query($q,$p = array())
{
    global $db;

    if($stmt = $db->prepare($query))
    {

        if(count($p) > 0)
        {
            foreach ($p as $key => $value) {
                $stmt->bindParam($key,$value);
            }
        }

        $stmt->execute();
        $resulSet = $stmt->fetchAll(PDO::FETCH_ASSOC);

        if(count($resulSet) > 0)
        {
            return true; // exists
        }
        else
        {
            return false; // does not exist
        }

    }

}
function isValidEmail ($email)
{
    if ($isemail=filter_var($email, FILTER_VALIDATE_EMAIL))
    {
        if(list($email,$domain) = explode('@',$email))
        {
            if(!getmxrr ($domain,$mxhosts)) 
            { 
                return FALSE; 
            }
            else 
            { 
                return TRUE; 
            }
        }
        else
        {
            return FALSE;
        }
    }
    else
    { 
    return FALSE; 
    } 

}