下拉列表值不存储在数据库中

时间:2016-01-30 13:00:07

标签: javascript php mysql mysqli

下拉列表值进入数据库。 但是再次获取值存储意味着不存储在数据库中。 这是一个注册表单,如部门值得db。 但是选择未存储在DB

中的值
<input class="form-last-name form-control" list="browsers" placeholder="Choose Dept"  id="dept" required/>
<datalist id="browsers">    
<option <?php
include "connect.php";
$query = mysqli_query($mysqli,"SELECT department FROM department");
$query_display = mysqli_query($mysqli,"SELECT department FROM department");
while($row=mysqli_fetch_array($query))
   {
     echo "<option value='". $row['department']."'>".$row['department'] .'</option>';
 }
   ?> ></option>
   </datalist>  
   </div>

register.php

    <?php
     include "connect.php";
    if(isset($_POST["submit"]))
     {
        $dept   = $_POST["dept"];
     $result = mysqli_query($mysqli, "INSERT INTO employee (Department)
            VALUES ('$dept')");

    if($result)
        {
            echo "<script>alert('New employee register successfully!')     </script>";
            echo "<script>window.open('register.php','_self')</script>";
        }

1 个答案:

答案 0 :(得分:0)

因为你的元素没有名字

<input name='dept' class="form-last-name form-control" list="browsers" placeholder="Choose Dept"  id="dept" required/>