我想使用选项-> MYSQL

时间:2018-07-24 19:44:44

标签: php html mysql

我目前有一个表单,其中的文本条目已正确输入到数据库中。

在最后一个条目上,我要将其从文本输入切换到下拉列表。这是我当前的代码:

    <div class="form-group">
    <label for="equipment">Equipment:</label>
    <input type="text" id="equipment" name="equipment" value="<?php echo isset($equipment) ? $equipment : ''; ?>" />
    <span class="validity"></span>
    </div>

这是我尝试将其切换为的代码:

<script type="text/javascript">

function showfield(name){

if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />';

else document.getElementById('div1').innerHTML='';

}

</script>



<select name="equipment" id="equipment" onchange="showfield(this.options[this.selectedIndex].value)">

<option value="53V" <?php echo (isset($equipment) && $equipment == '53V') ? 'selected="selected"' : ''; ?>">53v</option>
<option value="53R" <?php echo (isset($equipment) && $equipment == '53R') ? 'selected="selected"' : ''; ?>">53r</option>
<option value="53F" <?php echo (isset($equipment) && $equipment == '53F') ? 'selected="selected"' : ''; ?>">53f</option>
<option value="Other">Other</option>

</select>

<div id="div1"></div>

我完全关闭吗?

编辑:我根据Raptord的建议进行编辑

现在我得到:

错误2031 在准备好的语句中没有提供参数数据

已添加:

CREATE TABLE `details` (
  `id` int(11) UNSIGNED NOT NULL,
  `contactname` varchar(255) DEFAULT NULL,
  `phonenumber` varchar(255) DEFAULT NULL,
  `equipment` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

编辑(修订的代码):

<script type="text/javascript">

function showfield(name){

if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />';

else document.getElementById('div1').innerHTML='';

}

</script>

<div class="form-group">
<label for="equipment"><sup>*</sup> Equipment:</label>

<select name="equipment" id="equipment" onchange="showfield(this.options[this.selectedIndex].value)">
<option value="53V" <?php echo (isset($equipment) && $equipment == '53V') ? 'selected="selected"' : ''; ?>">53V</option>
<option value="53R" <?php echo (isset($equipment) && $equipment == '53R') ? 'selected="selected"' : ''; ?>">53R</option> 
<option value="53F" <?php echo (isset($equipment) && $equipment == '53F') ? 'selected="selected"' : ''; ?>">53F</option>
 <option value="Other">Other</option> </select> <div id="div1"></div>
</div>

1 个答案:

答案 0 :(得分:0)

您的选项标签应该看起来像这样,而不是具有2个值属性:

<option value="53V" <?php echo (isset($equipment) && $equipment == '53V') ? 'selected="selected"' : ''; ?>>53v</option>