Using PHP to remove a selected item from drop down

2019-02-28 17:03发布

问题:

Hiya: I'm trying to use PHP to remove selected item in a drop down menu, but all to know avail. Also, when I click on the same submit button that I'll use to remove selected list, I want to UPDATE the MySQL database. I tried using JavaScript, but couldn't use both languages on that submit input button.

This is my code for creating the drop down menu and button

$opts        = array("guns", "knives", "ammo");
$selected    = array($_POST['selectMenu']);
$revisedOpts = array_diff($opts, $selected);

HTML

<select name='selectMenu'>
<?php
foreach($revisedOpts as $v) {
     echo "<option>".$v."</option>";
}
?>
</select><input name="Collect" type="submit" value="submit" />

This is the mysql_query

if (isset($_POST['Collect'])) {
    mysql_query("UPDATE Player SET score = score+10
                 WHERE name = 'Rob Jackson' AND rank = 'Lieutenant'");
}