我有一个函数告诉我电子邮件是否在数据库中。我想知道的是,如果找到它,我怎么能同时传递像id,name etc
这样的变量以及它在数据库中找到的特定电子邮件。
function candidateInsert()
{
if($this->checkEmail($email))
{
echo 'found in db';
echo $email['id'];
}else{
echo 'error';
}
}
function checkEmail($email)
{
$email = $POST('Email');
if($email)
{
$candemail ="SELECT * FROM {table} WHERE email=?",$email"";
if(isset($candemail['email']))
{
return TRUE;
} else {
return FALSE;
}
}
}
答案 0 :(得分:0)
我将假设除了布尔值之外,您还希望返回id和名称。在这种情况下,通过引用传递参数:
function candidateInsert()
{
$id = "";
$name;
if($this->checkEmail($email, $id, $name))
{
echo 'found in db';
echo $id;
echo $name;
}else{
echo 'error';
}
}
function checkEmail($email, &$id, &$name)
{
$email = $POST('Email');
if($email)
{
$candemail ="SELECT * FROM {table} WHERE email=?",$email"";
if(isset($candemail['email']))
{
$id = $candemail['id'];
$name = $candemail['name'];
return TRUE;
} else {
return FALSE;
}
}
}
添加&在参数的开头,您可以编辑作为参数传递的变量的内容。
答案 1 :(得分:0)
如果你想回复一些邮件,你需要从CheckMail()函数返回值,如下所示:
function candidateInsert() {
$newmail = $this->checkEmail($email);
if($newmail != FALSE ) {
echo 'found in db';
echo $newmail['id'];
}else{
echo 'error';
}
}
function checkEmail($email)
{
$email = $POST('Email');
if($email)
{
$candemail ="SELECT * FROM {table} WHERE email=?",$email"";
$result = result($candemail ) // Don't know which sql functions u use
if(isset($result['email'])) {
return $result;
} else {
return FALSE;
}
}
}