这就是我所拥有的::
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<input type="hidden" name="email" value="<?php echo $email; ?>"/><br/>
<strong>Applicant ID:</strong> <?php echo $id; ?><br />
<strong>Applicant name: </strong>
<input type="text" name="username" readonly value="<?php echo $lastname. "," . $firstname. " " .substr($middlename, 0,1); ?>"/><br/>
<strong>Username: </strong><input type="text" readonly name="username" value="<?php echo $username; ?>" /> <br />
<strong>Password: </strong><input type="text" readonly name="password" value="<?php echo $password; ?>" /> <br />
<strong>Manage Application: </strong><select name="status">
<?php
$selection = array(
0 => "Pending",
1 => "Approve",
2 => "Revoke" );
foreach($selection as $key => $value)
{
echo '<option value="' . $key . '"';
if ($status == $key)
echo ' selected="selected"';
echo '>' . $value . '</option>';
echo ' <br />';
}
?>
</select>
<br />
<button type="submit" name="submit" value="Submit"><img src="../../images/login.png" />Update</button>
<?php
if(isset($_POST['submit']))
{
if($value == 'Approve'){
$to = $_POST['email'];
//define the subject of the email
$subject = 'BCE Scholars Application Notification';
//define the message to be sent. Each line should be separated with \n
$message = "Congratulations! Your application is approved.";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: bcescholar@yahoo.com\r\nReply-To: bcescholar@yahoo.com";
//send the email
if (mail($to, $subject, $message, $headers)) {
echo("<p>Congrats!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
}
if($value == 'Revoke')
{
$to = $_POST['email'];
//define the subject of the email
$subject = 'BCE Scholars Application Notification';
//define the message to be sent. Each line should be separated with \n
$message = "Sorry your application is revoked.";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: bcescholar@yahoo.com\r\nReply-To: bcescholar@yahoo.com";
//send the email
if (mail($to, $subject, $message, $headers)) {
echo("<p>Congrats!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
}
} // end of if button pressed
?>
<a href="../index.php"><button type="button"><img src="../../images/back.png"/>Back</button></a>
</div>
</form>
我的网站正在向其申请人发送电子邮件通知。如果管理员从组合框中选择批准,它将自动发送电子邮件,否则还将发送电子邮件通知申请人他的申请已被撤销/拒绝。但我的问题是它没有进入APPROVE if($ value =='Approve')语句。它总是进入REVOKE语句。这有什么问题?请帮忙。感谢。
答案 0 :(得分:2)
问题是,$value
只能在foreach($selection as $key => $value)
循环中访问,但您尝试在循环外使用 。您可以将值保存到临时数组,然后再使用它们
示例:强>
$tempArray = array();
foreach($selection as $key => $value)
{
echo '<option value="' . $key . '"';
if ($status == $key)
echo ' selected="selected"';
echo '>' . $value . '</option>';
echo ' <br />';
$tempArray[] = $value;
}
之后访问:
for($i = 0; $i < count($tempArray[]); $i++) {
// do what you want sith $tempArray[$i];
}
但我认为您想要做的是
if($_POST['status'] == 1)
检查您的组合框中是否选择了“批准”
答案 1 :(得分:0)
我已经解决了!
因为我保存了它的状态ID,所以我改为
if($_POST['status'] == 1)
感谢所有帮助过的人!