Using PHP to remove a selected item from drop down, amongst others

别等时光非礼了梦想. 提交于 2019-12-20 04:11:33

问题


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'");
}

来源:https://stackoverflow.com/questions/5192575/using-php-to-remove-a-selected-item-from-drop-down-amongst-others

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!