繁体   English   中英

php无法从组合框中获取正确的选定值

[英]php can't get into correct selected value from combobox

这就是我所拥有的::

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

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

我解决了!

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

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

感谢所有帮助过的人!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM