使用 PHP 从下拉列表中删除所选项目等
嗨: 我正在尝试使用 PHP 删除下拉菜单中的选定项目,但一切都知道有用。另外,当我单击用于删除所选列表的同一个提交按钮时,我想更新 MySQL 数据库。我尝试使用 JavaScript,但无法在提交输入按钮上使用两种语言。
这是我用于创建下拉菜单和按钮
$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" />
代码这是 mysql_query
if (isset($_POST['Collect'])) {
mysql_query("UPDATE Player SET score = score+10
WHERE name = 'Rob Jackson' AND rank = 'Lieutenant'");
}
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'");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论