Reputation: 475
I´m trying to run my code here but when i press on Send button it both somehow runs both Approve and Send. I think this is happening since this is inside a while loop, but i want only to execute Send function when it´s presend and same thing with Approve. All suggestions are welcome.
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 } ?>
Upvotes: 0
Views: 915
Reputation: 11342
This isn't doing what you think:
isset($_POST[$presentation_unapproved['profileid']]) == 'Approve'
isset
in this case is returning a bool
, so if it has anything at all, I imagine it's returning true, which you then ==
to 'Approve'
which is probably "logically" true.
You probably want to check that it's set at all (once), and then change behavior based on a string compare. So, something like so:
if (isset($_POST[$presentation_unapproved['profileid']])) {
if (strcmp($_POST[$presentation_unapproved['profileid'], "Send") {
...
} else if (strcmp($_POST[$presentation_unapproved['profileid'], "Approve") {
....
}
}
Upvotes: 1