当从下拉选择框中选择时,我需要存储用户选择的选项,当在表单中提交时,存储在MYSQL数据库中。
我已经有信息存储和显示良好,我只是试图添加更多的内容现在。我也试过用同样的方法,但我不能把它储存我想要的东西。
“选择”下拉列表在我的表单中如下所示:
<span> Difficulty: </span>
<select>
<option type="text" name="easy" id="easy" value="easy">easy</option>
<option type="text" name="comfortable" id="comfortable" value="comfortable">comfortable</option>
<option type="text" name="hard" id="hard" value="hard">hard</option>
<option type="text" name="veryhard" id="veryhard" value="veryhard">very hard</option>
<option type="text" name="hardest" id="hardest" value="hardest">Hardest ride in the world!</option>
</select>
</label>
我试着用这个发送它:
$difficulty = mysql_real_escape_string($_POST['difficulty']);
使用此查询:
$query = sprintf("INSERT INTO markers (difficulty) VALUES ('%s')", $difficulty);
当我的表设置为INT,20,allow null时,它在数据库中存储0。
当我设置VARCHAR,20,allow null时,它会存储一个空白字段。
我希望它存储用户选择的任何值,即简单、困难、非常困难等。
非常感谢
最佳答案
$_POST['difficulty']
将不保存值,因为未为选定对象指定“名称”。尝试
<select name="difficulty">
关于php - 在MySQL数据库,PHP中存储下拉选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5912394/