数据不会插入到数据库PHP中

时间:2016-03-17 11:25:03

标签: php

我试图将表单中的数据添加到数据库中。但它只是令人耳目一新。这是我的表单代码:

<form action="" method="post">
    <div id="modal1" class="modal modal-fixed-footer">
        <div class="modal-content">
            <h4>Bedroom</h4><br><br>
            <div class="row">
                  <div class="input-field col s6">
                      <i class="material-icons prefix">account_circle</i>

                      <input name="txt_room_ID" id="txt_room_ID" type="text" class="validate" readonly="true"
                             value="<?php 
                           $sql= "select * from tblBedroom";
                           $stmt = sqlsrv_query($con,$sql);
                           while($rs = sqlsrv_fetch_array($stmt)){
                               $Setting_adminID = $rs['BedRoomID'];
                               $adminID_new = str_replace("B","",$Setting_adminID);
                               $adminID = str_pad($adminID_new + 1,11,0,STR_PAD_LEFT);}
                                     echo htmlentities('B'. $adminID);
                           ?>">
                      <label for="room_ID">Bedroom ID:</label>
                  </div>

                   <div class="input-field col s6">
                      <i class="material-icons prefix">account_circle</i>
                      <input name="txt_bedroom_no" id="txt_bedroom_no" type="text" class="validate">
                      <label for="bedroom_no">Room Number</label>
                  </div> 
            </div>
            <div class="row">

                <div class="input-field col s12">
                    <select name="txt_Room_Type">
                      <option value="" disabled selected>Choose Room Type</option>
                        <?php
                        $sql = "select * from tblBedRoomType";
                        $stmt = sqlsrv_query($con,$sql);
                            while($rs = sqlsrv_fetch_array($stmt)){
                                $BedroomTypeID = $rs['BedroomTypeID'];
                                $BedroomName   = $rs['BedroomName'];

                                echo"<option value='$bedroomTypeID'>$BedroomName</option>";

                            }
                        ?>
                    </select>
                    <label>Room Type</label>
                </div>
            </div>
        </div><!--END OF MODAL CONTENT-->
        <div class="modal-footer">
            <a class="modal-action modal-close waves-effect waves-green btn-flat ">Cancel</a>
                <input id="btn_Save" name="btn_Save" type="submit" value="Save" class="waves-effect waves-green btn-flat " onclick="return confirm('Are You Sure You Want To Save?');">
        </div>
    </div>  
 </form>

表单下方的php

 <?php
if(isset($_POST['btn_Save'])){
        $txt_room_ID =          $_POST['txt_room_ID'];
        $txt_bedroom_no =       $_POST['txt_bedroom_no'];
        $txt_Room_Type =        $_POST['txt_Room_Type'];
        $AcctStat = 1;
$sql = "insert  into tblBedRoom (BedRoomID,BedroomType,RoomNo,AcctStat)  
values('$txt_room_ID','$txt_Room_Type','$txt_bedroom_no','$AcctStat')";
$stmt = sqlsrv_query($con,$sql);
echo "<meta http-equiv='refresh' content='0'>";   

 }
?>

我的tblBedRoom中的列是: BedRoomID | BedroomType | RoomNo | AcctStat

0 个答案:

没有答案