douchan7552 2015-07-31 15:59
浏览 19

从html输入值不会进入数据库表[关闭]

I have created a html form and and a database to store the inputs from user. Here is the html form code

<form class="form" method="post" action="data.php">
                    <div class="form-group">
                        <input class="form-control input-lg" type="text" placeholder="Full Name" name="name" id="name" required="">
                    </div>
                    <div class="form-group">
                        <input class="form-control input-lg" type="tel" placeholder="Phone Number" name="phone" id="phone" required="">
                    </div>
                    <div class="form-group">
                        <input class="form-control input-lg" type="email" placeholder="Email ID" name="email" id="email" required="">
                    </div>
                    <div class="form-group">
                        <input class="form-control input-lg option" type="date" name="date" value="Date" id="date" required="">
                    </div>
                    <div class="form-group">
                        <select class="form-control input-lg option" name="time" id="time" style="padding-left: 10px;">
                          <option>Time Slot</option>
                          <option>10:00-11:00</option>
                          <option>11:00-12:00</option>
                          <option>12:00-13:00</option>
                          <option>13:00-14:00</option>
                          <option>14:00-15:00</option>
                          <option>15:00-16:00</option>
                          <option>16:00-17:00</option>
                        </select>
                    </div>
                    <input class="btn btn-success btn-lg" style="margin-left: 30%; margin-top:10px; padding: 5px 16px;" type="submit" value="BOOK">
                    
                </form>

and data.php file is

<?php 
   

$servername = "localhost";
$username = "root";
$password = "user";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "INSERT INTO data (name, phone, email, date, time)
VALUES ('$_POST[name]', '$_POST[phone]', '$_POST[email]',  '$_POST[date]', '$_POST[time]')";

echo "Connected successfully";
?>

So when i input some values in html form it shows connected successfully but in database no inputs are showing in data table.

So please help me to solve this issue.

</div>
  • 写回答

1条回答 默认 最新

  • dtkmejg127475 2015-07-31 16:06
    关注

    As far as I can see you have two problems here:

    • You connect to the server, but you don't select a database
    • You have to execute your query with: mysqli_query($sql)
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端