dongxin5054 2014-03-27 16:58
浏览 28
已采纳

php代码没有使用bootstrap表单插入我的phpmyadmin表中的所有内容

I am working on a bootstrap form using phpmyadmin database. I can't get any data into my table when I fill out the form using insert statement. I don't any error and it doesn't tell me that I am not connected to the database. How can I insert my data into the database when I use the form ?

this is my php code

    <?php
    $con=mysqli_connect("localhost","username","password","database");
    // Check connection
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $sql="INSERT INTO entries (Name, Email, Age, Message)
    VALUES
    ('$_POST[name]','$_POST[email]','$_POST[age]','$_POST[message]')";

    if (!mysqli_query($con,$sql))
      {
    die('Error: ' . mysqli_error($con));
    }
    echo "1 record added";

    mysqli_close($con);
    ?>

form code

<div style="margin-top:50px">
        <div class="container">
          <div class="panel panel-default" style="margin:0 auto;width:500px">
            <div class="panel-heading">
              <h1>Enter to win!</h1>
            </div>
            <div class="panel-body">
              <form name="entryform" method="post" action="" class="form-horizontal" role="form">
                <div class="form-group">
                  <label for="inputName" class="col-lg-2 control-label">Name</label>
                  <div class="col-lg-10">
                    <input type="text" class="form-control" id="Name" name="Name" placeholder="Your Name">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail" class="col-lg-2 control-label">Email</label>
                  <div class="col-lg-10">
                    <input type="email" class="form-control" id="Email" name="Email" placeholder="Your Email">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputAge" class="col-lg-2 control-label">Age</label>
                  <div class="col-lg-10">
                    <input type="text" class="form-control" id="Age" name="Age" placeholder="What is your current age?">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputMessage" class="col-lg-2 control-label">Message</label>
                  <div class="col-lg-10">
                    <textarea class="form-control" rows="4" id="Message" name="Message" placeholder="What will you do with the prize?"></textarea>
                  </div>
                </div>
                <div class="form-group">
                  <div class="col-lg-offset-2 col-lg-10">
                    <button type="submit" class="btn btn-default">
                      Enter to win!
                    </button>
                  </div>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>

when I enter data from the form I get blank except id and timestamp

enter image description here

  • 写回答

1条回答 默认 最新

  • duanji1482 2014-03-27 17:55
    关注

    Try changing the names in your query. Change "$_POST[name]" to "$_POST[Name]", "$_POST[email]" to "$_POST[Email]", "$_POST[age]" to "$_POST[Age]", "$_POST[message]" to "$_POST[Message]".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程