0

这就是我所拥有的::

     <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 语句。这有什么问题?请帮忙。谢谢。

4

2 回答 2

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)检查您的组合框中是否选择了“批准”

于 2013-02-07T07:20:57.987 回答
0

我已经解决了!

因为我保存了它的状态ID,所以我改为

    if($_POST['status'] == 1)

感谢所有帮助过的人!

于 2013-02-07T07:34:11.917 回答