簡體   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