在MySQL数据库,PHP中存储下拉选项 [英] store drop down options in mysql database, PHP

查看:241
本文介绍了在MySQL数据库,PHP中存储下拉选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从下拉选择框中选择用户选择的选项时,我需要存储该用户选择的选项,并在以表单提交时将其存储在我的MYSQL数据库中.

I need to store the user selected option when chosen from my drop down select box, and when submitted in my form, store in my MYSQL database.

我已经可以很好地存储和显示信息了,我现在正尝试添加更多内容.我尝试使用相同的方法,但是我无法获取它来存储我想要的东西.

I already have information being stored and displayed fine, i am just trying to add more content now. I have tried using the same method, but i cant get it to store what i want.

select下拉列表在我的表单中看起来像这样:

The select drop down looks like this inside my form:

  <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>

并且我正在尝试使用以下方式发送它:

and i am trying to send it using this:

    $difficulty = mysql_real_escape_string($_POST['difficulty']);

使用此查询:

$query = sprintf("INSERT INTO markers (difficulty) VALUES ('%s')", $difficulty);

当我的表设置为INT,20时,允许为空,它将在数据库中存储0. 当我将其设置为VARCHAR(20)时,允许为空,它将存储一个空白字段.

When my table is set up as INT, 20, allow null, it stores 0 in the database. and when i set it up VARCHAR, 20, allow null, it stores a blank field.

我希望它存储用户选择的任何值,即简单,困难,非常困难等.

i want it to store whichever value the user chooses, i.e easy, hard, very hard etc.

非常感谢

推荐答案

$_POST['difficulty']

将不保存值,因为未为SELECT赋予名称".试试

Would not hold a value as the SELECT has not been given a 'name'. Try

<select name="difficulty">

这篇关于在MySQL数据库,PHP中存储下拉选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆