PHP - 检查是否存在

时间:2013-11-26 06:17:49

标签: php email

我正在努力解决这个问题。我想检查一下memusers表中是否存在记录。如果确实发送并发送电子邮件。如果没有,请添加到表中。我只是忽略了什么?谢谢!

    //**********  Check if specific record exists  ************
global $conn;
$strSQLExists = "select * from memusers where Email='".$values["Email"]."'";
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);
if($data)
{

//**********  Send email with new data  ************

$email='".$values["Email"]."';
$from="admin@test.com";
$msg="Welcome!";
$subject="Welcome!";

foreach($values as $field=>$value)
{
    if(!IsBinaryType($pageObject->pSet->getFieldType($field)))
        $msg.= $field." : ".$value."\r\n";
}

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
if(!$ret["mailed"])
    echo $ret["message"];
}
else
{
    $strSQLInsert = "insert into memusers(Email, AccessType) values ('".$values["Email"]."','".$values["Accesstype"]."')";
CustomQuery($strSQLInsert);
}

return true;

2 个答案:

答案 0 :(得分:0)

尝试这样的事情

$strSQLExists = "select * from memusers where Email='".$values["Email"]."'";
$rsExists = mysql_query($strSQLExists,$conn);
$data=mysql_fetch_array($rsExists);
$num = mysql_num_rows($data);
if($num == 0)
{
//do something
}
else
{
//do something
}

答案 1 :(得分:0)

$email='".$values["Email"]."';错误的代码应为$email=$values["Email"];