我无法从 html 表单中提取数据到 mySQL DB

问题描述 投票:0回答:0

我正在使用 linux 操作系统,我已经安装了 xmapp 服务器,我还创建了一个数据库“User_Information”,我正在尝试将表单数据从我的 html 文件提交到数据库。

我把php文件放在如下目录。 opt/lampp/htdocs 并在 html 表单中指定相同的路径。下面是我的代码。

**<form id="myForm"  action="/opt/lampp/htdocs/connect.php" method="post">**
                        <p class="h4 mb-4 text-center">Enter Your Complaint Details</p>
                        <!-- FirstName -->
                        <div class="form-group">
                            <label for="local">First Name</label>
                            <input type="text" class="form-control" id="local" name="first_name">
                        </div> 
                        <!-- LastName -->
                        <div class="form-group">
                            <label for="local">Last Name</label>
                            <input type="text" class="form-control" id="local" name="last_name">
                        </div> 
                        <!-- Date input -->
                        <div class="form-group">
                            <label for="date">Date:</label>
                            <input type="text" class="form-control datepicker" id="date" name="date" required>
                        </div>
                        <!-- Address-->
                        <div class="form-group">
                            <label for="local">Address</label>
                            <input type="text" class="form-control" id="local" name="Address">
                        </div> 
                        <!--LandMarkOfArea-->
                        <div class="form-group">
                            <label for="local">Enter a key Land Mark of your Area</label>
                            <input type="text" class="form-control" id="local" name="LandMarkOfArea">
                        </div> 
                        <!--Number Of Network Bars-->
                        <div class="form-group">
                            <label for="carro">Number Of Network Bars</label>
                            <select class="form-control" id="carro" name="bars">
                                <option selected disabled hidden style='display: none' value=''></option>
                                <option value="1 bar">1 bar</option>
                                <option value="2 bars">2 bars</option>
                                <option value="3 bars">3 bars</option>
                                <option value="4 bars">4 bars</option>
                                <option value="5 bars">5 bars</option>
                                <option value="full-bars">full bars</option>
                            </select>
                        </div>    
                        <!--LandMarkOfArea-->
                        <div class="form-group">
                            <label for="local">Enter The Device Type</label>
                            <input type="text" class="form-control" id="local" name="deviceType" placeholder="e.g phone x, or samsung">
                        </div>
                        <!--Frequency/How Often this has occurred-->
                        <div class="form-group">
                            <label for="carro">How often this problem has occurred</label>
                            <select class="form-control" id="carro" name="frequency">
                                <option selected disabled hidden style='display: none' value=''></option>
                                <option value="1 time">1 time</option>
                                <option value="2 times">2 times</option>
                                <option value="3 times">3 times</option>
                                <option value="More">more than</option>
                            </select>
                        </div>   
                        <!--Duration-->
                        <div class="form-group">
                            <label for="local">For How Long has this Problem Persisted</label>
                            <input type="text" class="form-control" id="local" name="duration" placeholder="e.g 5 days, six days...">
                        </div>

                                <!--Other Users Expeririencing a similar problem-->
                                <div class="form-group">
                                    <label for="yes-no">Are there other users experiencing the same:</label><br>
                                    <div class="form-check form-check-inline">
                                      <input class="form-check-input" type="radio" name="yes-no" id="yes-option" value="yes">
                                      <label class="form-check-label" for="yes-option">Yes</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                      <input class="form-check-input" type="radio" name="yes-no" id="no-option" value="no">
                                      <label class="form-check-label" for="no-option">No</label>
                                    </div>
                                  </div>
                           <!--Problem Description-->
                          <div class="form-group">
                            <label for="text-area">Complaint Details</label>
                            <textarea class="form-control" id="text-area" name="text-area" rows="3" placeholder="Type something here..."></textarea>
                          </div>
                            
                           <!--Coordinates-->
                          <div class="form-group">
                            <input type="hidden" class="form-control" id="lat" name="lat">
                            <input type="hidden" class="form-control" id="long" name="long">
                          </div>
  
                          <button type="submit" class="btn btn-primary btn-block">Submit</button>
                      </form>

以下是我的php代码

<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$date = $_POST['date'];
$address = $_POST['Address'];
$landmark = $_POST['LandMarkOfArea'];
$network_bars = $_POST['network_bars'];
$device_type = $_POST['deviceType'];
$duration = $_POST['duration'];
$frequency = $_POST['frequency'];
$OtherPeopleExperience = $_POST['yes-no'];
$coordinates = $_POST['lat'];
$ComplaintDetails = $_POST['text-area']; 

$conn = new mysqli('localhost','root','','User_Information');

if($conn->connect_error){
    echo "$conn->connect_error";
    die("Connection Failed : ". $conn->connect_error);
} else {
    $stmt = $conn->prepare("insert into CustomerComplaintDetails(FirstName, LastName, Date, Address, LandMarkOfArea, DeviceType, NumberOfNetworkBars, duration, Frequency, OtherCustomersExperiencingTheSame, Coordinates, ProblemDescription) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("ssssssssssds", $first_name, $last_name, $date, $address, $landmark, $device_type, $network_bars, $duration, $frequency, $OtherPeopleExperience, $coordinates, $ComplaintDetails);
    $execval = $stmt->execute();
    echo $execval;
    echo "Registration successfully...";
    $stmt->close();
    $conn->close();
}
?>

当我点击提交按钮时没有任何反应,我没有收到任何错误消息或任何表明我的数据已提交的信息 我可能做错了什么或者我没有做什么?

php html mysql mysqli html-formhandler
© www.soinside.com 2019 - 2024. All rights reserved.