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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog