如何检查邮件是否存在于MySQL…?
public function AddReseller($name,$businessName,$businessPageName,$contactNumber,$fullAddress,$email)
{
$db = new Mysqlidb();
if(!$db) die("Database error");
$data = Array(
'Name' => $name,
'BusinessName' => $businessName,
'Address' => $fullAddress,
'ContactNumber'=>$contactNumber,
'Email'=>$email,
'PageName'=>$businessPageName
);
if($email > 0)
{
echo "Email Exists Already";
}
$id = $db->insert ('tenterprise', $data);
return $id;
}
这是代码和$db->是插入查询表…!帮帮我……!
哇,你是相当糟糕的问问题:)你正在检查$email参数,你发送作为参数的函数,但你想检查如果该电子邮件已经在数据库中,你试图将此数据数组添加到表之前。在这种情况下,很明显,您需要首先在表上使用已发送参数$email执行select查询,如下所示:
$checkquery = "select email from tenterprise where email = ".$email;
那么您应该检查此查询是否有任何结果。如果result为空,则表示该电子邮件以前未被使用过。
当你问问题的时候,试着更具体地说明你想要达到的目标,这样别人就可以专注于正确的事情来帮助你!代码可能是这样的:为了获得这项工作,您必须连接到数据库。
<?php
$result =mysql_query("SELECT email FROM table WHERE `email` = 'test@sample.com'");
if ($result && mysql_num_rows($result) > 0){
echo 'Email Found';
}else{
echo 'Email not Found';
}
?>
我看到你正在使用mysqlidb。对于mysqlidb,你可以使用where ()->get()来避免写sql.
public function AddReseller($name,$businessName,$businessPageName,$contactNumber,$fullAddress,$email)
{
$db = new Mysqlidb();
if(!$db) die("Database error");
$data = Array(
'Name' => $name,
'BusinessName' => $businessName,
'Address' => $fullAddress,
'ContactNumber'=>$contactNumber,
'Email'=>$email,
'PageName'=>$businessPageName
);
if($user = $db->where("email", $email)->get ('tenterprise')) > 0)
{
echo "Email Exists Already";
return $user['id'];
}
$id = $db->insert ('tenterprise', $data);
return $id;
}