0

我正在尝试在这里运行我的代码,但是当我按下Send按钮时,它都以某种方式同时运行 Approve 和 Send。我认为这种情况正在发生,因为这是在一个 while 循环内,但我只想在它的 presend 和 Approve 相同的情况下执行 Send 函数。欢迎所有建议。

干杯!;)

<?php 
//0 = No presentation
//1 = Presentation under review
//2 = Presentation approved
//3 = Presentation declined

//GET ALL PRESENTATIONS WHICH NEEDS TO BE APPROVED APPROVED
while($presentation_unapproved = mysql_fetch_array($approve_presentation)){

$display_user_id_presentation = mysql_real_escape_string($presentation_unapproved['profile_user_id']);
$display_presentation_id = mysql_real_escape_string($presentation_unapproved['profileid']);
//Här går vi in i users tabellen och hämtar all nödvändig information om själva användaren
$who_is_user_unapp = mysql_query("SELECT id, s_id, user_name, gender, user_age, profile_image_url, country FROM users WHERE id='$display_user_id_presentation'");
$who_is_user_show_unapp = mysql_fetch_array($who_is_user_unapp);

if (isset($_POST[$presentation_unapproved['profileid']]) == 'Send') 
            {
                $what_reason = $_POST['decline_reason'];
                echo $what_reason;
            }

//Approve presentation
    if (isset($_POST[$presentation_unapproved['profileid']]) == 'Approve') 
            {
                //$presid_number = mysql_real_escape_string($presentation_unapproved['profileid']);
                //mysql_query("UPDATE profile_info SET profile_text_approved='2' WHERE profileid='$presid_number'");
                //header('Location: '.selfURL());       
                echo "this should not be output";
            }


?>

<div class="main">
<div class="main_left">
    <div class="inside">
        <div class="inside_left">
            <img src="<?php echo $path_90_120_image;?><?php echo $who_is_user_show_unapp['profile_image_url'];?>">
            <br>
            <b><?php echo $who_is_user_show_unapp['user_name'];?></b><br>
                <?php echo $who_is_user_show_unapp['country'];?><br><br>
        </div>
        <div class="inside_right"><?php echo $presentation_unapproved['profile_text'];?></div>
    </div>
</div>
<div class="main_right">
    <form method="post" action="">
    <input type="submit" class="approve" value="Approve" name="<?php echo $presentation_unapproved['profileid'];?>"><br>
    <input type="submit" class="decline" value="Decline"><br>
    <input type="submit" class="warning" value="Warn user"><br>
    <b>

    <?php


    $words = $presentation_unapproved['profile_text'];
    print_r( strlen($words) );
    ?> chars written</b>
    <br><br>
    <div id="panel">
        <b>Decline reason</b>
        <?php 
        //Get all decline reasons
        $decline_reasons = mysql_query("SELECT * FROM admin_messages_default WHERE category = 'Presentation'");
        ?>
        <br><br>
        <select name="decline_reason">
            <?php
            while($decline_reasons_view = mysql_fetch_array($decline_reasons)) {


            ?>
            <option value="<?php echo $decline_reasons_view['id'];?>"><?php echo $decline_reasons_view['title'];?></option>
            <?php } ?>
        </select>   <br><br>
        <input type="submit" value="Send" name="<?php echo $presentation_unapproved['profileid'];?>">
    </div>
    </form>
</div>

<?php } ?>
4

1 回答 1

1

这不是你想的那样:

isset($_POST[$presentation_unapproved['profileid']]) == 'Approve'

isset在这种情况下返回 a bool,所以如果它有任何东西,我想它会返回 true,那么你==可能'Approve'会“逻辑上”为 true。

您可能想要检查它是否已设置(一次),然后根据字符串比较更改行为。所以,像这样:

if (isset($_POST[$presentation_unapproved['profileid']])) {
  if (strcmp($_POST[$presentation_unapproved['profileid'], "Send") {
    ...
  } else if (strcmp($_POST[$presentation_unapproved['profileid'], "Approve") {
    ....
  }
}
于 2013-02-07T22:31:03.940 回答