php记录没有插入

时间:2015-06-07 18:28:41

标签: php mysql pdo

我无法在mysql中插入记录,这里是html& php代码

HTML

 <form id="fForm" action="insert_staff_2.php" method="POST" enctype="multipart/form-data">
<select name="gender" id="gender" class="formTxtInput" onkeyup="getStaffId()"> 
    <option>Gender</option>
    <option>Female</option>
    <option>Male</option>
</select>

PHP

    include  '../mysql_connect.php';
$db = new DBConfig();
$conn = $db->getDbPDO();
if(isset($_POST['gender'])){
$gender = $_POST['gender'];
$sql = "INSERT INTO tbl_staff (gender) VALUES (?)";
$query = $conn->prepare($sql);
$query->execute(array($gender)); 
echo"record enterd";
}else{
echo"record Not enterd"; }

2 个答案:

答案 0 :(得分:1)

您似乎没有从表单中传递任何值。请务必在options标记中设置'value'属性,如下所示:

<option value='1'>Gender</option>
<option value='2'>Female</option>
<option value='3'>Male</option>

答案 1 :(得分:0)

验证您的html表单:

<form id="fForm" action="insert_staff_2.php" method="POST" enctype="multipart/form-data">
<select name="gender" id="gender" class="formTxtInput" onkeyup="getStaffId()"> 
<option value="">Gender</option>
<option value="Female">Female</option>
<option value="Male">Male</option>
</select>
</form>