I'm working on a website for Pokemon Go, and as part of the site I'm making a custom CMS that allows me to insert/alter data for displaying on various webpages. I want to be able to toggle a Raid Boss to "inactive" based on the boss selected in a drop down menu.
The following is the HTML code for the form where the dropdown is located. Basically I query the database of Raid Bosses for all bosses that are currently active, or "1", and append them to the option list:
<h5 style="text-decoration: underline;">Set Active Raid Boss to Inactive</h5>
<form class = "form-group" method = "post">
<select>
<option disabled selected value> -- select an option -- </option>
<?php
$prep_stmt = $conn->prepare("SELECT * FROM raids WHERE isActive = 1");
$prep_stmt->execute();
$row = $prep_stmt->fetchAll();
$count = $prep_stmt->rowCount();
for($x = 0; $x < $count; $x++) {
echo "<option name ='".$row[$x]['name']."' value='".$row[$x]['name']."'>". $row[$x]['name']. "</option>";
}
?>
</select>
<input name = "ToggleToInactiveRaid" type = "submit" value="Submit"/>
</form>
The following is the PHP code for the $_POST request when the button is clicked:
if(isset($_POST['ToggleToInActiveRaid'])){
$raids = $conn->prepare("SELECT * FROM raids WHERE isActive = 1");
$raids->execute();
$raidList = $raids->fetchAll();
$count = $raids->rowCount();
for($i = 0; $i < $count; $i++){
if ($raidList[$i]['name'] == $_POST['name']){
$stmt = $conn->prepare("UPDATE raids SET isActive = 0 WHERE raids.name = ".$_POST['name']);
$stmt->execute();
}
}
}
For some reason, the POST request is never detected. I know this because I was echoing a dummy variable in the form section that would only be displayed if its value was updated in the POST request if block, and that variable was never dumped onto the page. I have other forms on the CMS page where the PHP code is executed when the respective button is clicked. But this one is giving me quite a bit of trouble and I really don't know why. If anyone can help me out, that would be awesome. Thanks!
$_POST['ToggleToInActiveRaid']is processed reside in the same file as where its submitted??) should be used in the SQL and the values should be bound in theexecuteor abindparamcall. See php.net/manual/en/pdostatement.execute.php