在php循环中提交表单

时间:2013-02-07 22:23:28

标签: php html forms loops if-statement

我试图在这里运行我的代码但是当我按下发送按钮时,它以某种方式运行批准和发送。我认为这是发生的,因为这是在一个while循环中,但我只想在presend时执行Send函数,并且与Approve相同。欢迎所有建议。

Cheerz! ;)

<?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 } ?>

1 个答案:

答案 0 :(得分:1)

这不符合你的想法:

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

在这种情况下,

isset返回bool,所以如果它有任何内容,我想它会返回true,然后你=='Approve'可能“逻辑上”是真的。

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

if (isset($_POST[$presentation_unapproved['profileid']])) {
  if (strcmp($_POST[$presentation_unapproved['profileid'], "Send") {
    ...
  } else if (strcmp($_POST[$presentation_unapproved['profileid'], "Approve") {
    ....
  }
}