我希望我的“提交”按钮能够在单击时运行if else语句。在我的用户表的“完成”字段中,如果该值是6或更高,则应该发送一封电子邮件(我有此代码),否则,它应该显示错误或重定向到错误页面(可以创建)。这是我的尝试,但是即使该值为6也会显示错误消息
$usr_email = 'usr_email';
$user_name = 'user_name';
{
$sqltest = "SELECT complete From users where user_id =
".intval($_SESSION['user_id']);
}
if (isset($_POST['doSend'])) {
function getOne($query){
$res = mysql_query($query);
if (!$res) {
trigger_error("db: ".mysql_error()." in ".$query);
return FALSE;
}
}
if ($row = mysql_fetch_row($res)) {
return $row[0];
}
$isSending = getOne($sqltest);
$isSending === false;
if($isSending >= 6){
require_once "Mail.php";
$from = "<xxx>";
$to = "$usr_email";
$subject = "Hi";
$body = hello ";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "xxx";
$password = "xxx";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
header ("Location: error.php");
}
}
}
最佳答案
更改
<p align="center">
<input name="doSend" type="submit" id="doSend" value="Submit Application">
</p>
至
<form name="input" action="myaccount.php" method="post">
<input name="doSend" type="submit" id="doSend" value="Submit Application">
</form>
您需要在外部
else
语句中添加if
。$isSending = getOne($sqltest);
$isSending === false;
if($isSending >= 6){
require_once "Mail.php";
$from = "<xxx>";
$to = "$usr_email";
$subject = "Hi";
$body = hello ";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "xxx";
$password = "xxx";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
}
else
header ("Location: error.php");
关于php - 提交按钮不起作用-否则声明,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10216394/