即使选择了一个选项,html选择标记也需要说明

时间:2017-02-11 20:21:03

标签: php html

我的html表单中有一个下拉列表,即使我从中选择了一个选项,它仍然说我应该在列表中选择一个项目,当我删除所需的属性并提交时,它不会输入选项i选入数据库。

这是我的代码

      <form style="margin-bottom: 5%;" method="POST" action="generate-invoive-results-service.php">

                   <?php 
                     $query="SELECT diagnosis FROM medications WHERE diagnosis LIKE '%" . $_COOKIE['searchdisease'] . "%'";
                     $result= $con->query($query);
                    ?>  
                          <select required="true" id="nol" style="width: 40%; margin-left: -1%;" name="tdisease" data-toggle="tooltip" data-original-title="medications" class="date-picker form-control col-md-7 col-xs-12" data-rel="chosen">
                            <option value="">Select Disease</option>
                             <?php while ($row=$result->fetch_array(MYSQLI_ASSOC)) { ?>
                            <option value="<?php echo $row['ICD10']?>"><?php echo $row['diagnosis'];?> </option> 
                      <?php } ?> 
                         </select><br>
                <input class="btn btn-warning" style="width: 170px; margin-left: -7%; margin-top: -1%; margin-bottom: 1%; color: #000;" type="submit" name="insertData" value="Create Invoice"> 
  </form>
<?php
if(isset($_POST['insertData']))
{
    $pred =$_POST['pre']; 
    $np =$_POST['nap']; 
    $sd10 =$_POST['tdisease'];
    $pr =$_POST['pric'];  
    $ivd =$_POST['invd'];
    $id =$_POST['user'];

      $insert_user="INSERT INTO invoices(id, icd10, nappi_code, prescription, price, invoice_date, pid) VALUES ('','$sd10', '$np' ,'$pred','$pr','$ivd','$id')";

    if(mysqli_query($con,$insert_user))
    {  
        echo"<script>alert(' Invoice Details successfuly added to database')</script>";
        echo '<meta content="1;generate-invoive-results-service-add.php?id='.$id.'" http-equiv="refresh" />';// redirects user view page after 3    
    }else{  
        echo"<script>alert('Unknown error occured')</script>";   
  } 
}
?>

1 个答案:

答案 0 :(得分:0)

虽然它不应该有所作为,但你应该注意到你重复:

required="true"

如果您可以显示从PHP生成的HTML代码,则可能有助于解决问题。