Jump to content

[SOLVED] POST from Dropdown Box ?


grahamb314

Recommended Posts

Hi All

I have a page which selects data from a database correctly and it displays it all fine within the dropdown box. And then I want to delete what I select from the dropdown box

 

The problem is when I press delete, the selected item from the dropdown box does not POST to the php page (Which is perfectly designed to delete the POST variable)

 

I want 'select' to be what i select and then 'select' to be the post variable in the 2nd page

 

Any help would be fantastic!

 

index page:

 

<html>
<head>
<title></title>
</head>
<body>
<div align="center"></div>

<div align="center"><img src="Purple_Logo.jpg" width="300" height="113"></div>

<form action="mysql_delete_show.php" method="POST"><select name="select">
<?php
require_once 'mysql_connect.php';  // this connects to the databse correctly //
$DJshows = mysqli_query($mysqli, "SELECT * FROM shows");
while ($show = mysqli_fetch_assoc($DJshows)) {  
echo "<option value=\"{$show['show']}\">{$show['show']}</option>";
}
?>
</select>
        <input type="submit" value="Delete">
  </p>

</form>

</form>
    

<input name="BUTTON3" type="BUTTON" onClick="javascript:history.go(-1)" value="Back">
</body>
</html>

 

and here is the mysql_delete_show.php code

 

<?php 
require_once 'mysql_connect.php';
$query = "DELETE FROM `shows` WHERE `shows`.`show` ='{$_POST["option"]}';";
mysqli_query($mysqli, $query) or die("Query:{$query} <br>Error:".mysqli_error($mysqli));
echo "<p>If there are no errors, the show <b> ".$_POST["option"]." </b> has been deleted from the database!";
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/124174-solved-post-from-dropdown-box/
Share on other sites

you name your 'select' select, but then you check $_POST["option"] instead of $_POST["select"]. select is the name of the form element you want to check, not option.

 

$query = "DELETE FROM `shows` WHERE `shows`.`show` ='{$_POST["select"]}';";

 

p.s. i wouldn't name any form element select, especially not a 'select' form element. too confusing. i'd name it something more like 'toDelete' or something:

 

<select name="toDelete">

 

then

 

$toDelete = mysql_real_escape_string($_POST['toDelete']);
$query = "DELETE FROM `shows` WHERE `show` = '$toDelete';";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.