dpr81047 2015-09-28 20:26
浏览 76
已采纳

提交按钮不会将表单数据发送到MySQL数据库[关闭]

I have a problem that might be a syntax problem but I can't seem to figure out what I am doing wrong. I have created a form and when I click on submit, the data in the form is not sent to my mysql database.

Here is my html code

<div class="content-wrapper">
  <div class="container">
    <div class="row">
      <div class="col-md-10">
        <h1 class="page-head-line">Forms </h1>
      </div>
    </div>
    <div class="row">
      <div class="col-md-10">
        <div class="panel panel-default">
          <div class="panel-heading">
            BASIC  FORM ELEMENTS
          </div>
          <div class="panel-body">
            <form method="post" action="insert.php" >
              <div class="form-group">
                <label for="name">Name</label>
                <input name="name' type="text" class="form-control" id="name" placeholder="Enter your name"  required/>
                                                                                                           </div>
                       <div class="form-group">
                         <label for="project_num">OIT-GIS Project Number</label>
                         <input name="project_num' type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
                                                                                                                                         </div>
                                <div class="form-group">
                                  <label for="project_name">Project Name</label>
                                  <input name="name' type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
              </div>
              <div class="form-group">
                <label for="easyvista">EasyVista Ticket Number</label>
                <input name="easyvista' type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
                       </div>
                       <div class="form-group">
                         <label for="agency">Requestor/Agency</label>
                         <input name="agency' type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
                                </div>
                                <div class="form-group">
                                  <label for="description">Description of Work:</label>
                                  <input name="description' type="text" class="form-control" id="agency" placeholder="Description" />

              </div>
              <div class="form-group">
                <label for="input-date">Enter Today Date</label>
                <input name="input-date' type="date" value="">
                         <span class="result"></span>
                       </div>
                       <div class="form-group">
                         <div class="col-md-10">
                           <input id="submit" name="submit" type="submit" class="btn btn-primary">
                         </div>
                       </div>
            </form>


          </div>
        </div>

and here is my php

<?php

echo $POST;
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
    include("../includes/config.php");

 if (isset($_POST['submit'])) {
        echo $_POST['submit'];
        $name = $_POST['name'];
        $projectnum = $_POST['project_num'];
        $projectname = $_POST['project_name'];
        $easyvista = $_POST['easyvista'];
        $agency = $_POST['agency'];
        $description = $_POST['description'];
        $startDate = $_POST['input-date'];

    $sql="INSERT INTO statusreport(name, project_num, project_name, easyvista, agency, description)
            VALUES
            ('$name','$projectnum', '$projectname', '$easyvista', '$agency', '$description')";         

    if (!mysqli_query($conn, $sql))
      {
      die('Error: ' . mysqli_connect_error($conn));
      }
    echo "Entry is recored <br/>";
    echo "Name:", $name, "<br/>";
    echo "test..................<br/>", $name;
     /*header("location: http://10.1.7.129//gisadmin/admin/forms.php");*/

    //echo "<script>setTimeout(\"location.href = 'http://10.1.7.129//gisadmin/admin/forms.php';\",700);</script>";
    mysqli_query($conn, $sql);
}
else {
    echo "No data";
}
?>

Any help would be greatly appreciated. Thanks

  • 写回答

2条回答 默认 最新

  • douxueke5653 2015-09-28 20:28
    关注

    You have a mixing of single and double quotes here, the name attributes are opening the value with double quotes and closing with single quotes, should be as follows:

    <form method="post" action="insert.php" >
        <div class="form-group">
            <label for="name">Name</label>
            <input name="name" type="text" class="form-control" id="name" placeholder="Enter your name"  required/>
        </div>
        <div class="form-group">
            <label for="project_num">OIT-GIS Project Number</label>
            <input name="project_num" type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
        </div>
        <div class="form-group">
            <label for="project_name">Project Name</label>
            <input name="project_name" type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
        </div>
        <div class="form-group">
            <label for="easyvista">EasyVista Ticket Number</label>
            <input name="easyvista" type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
        </div>
        <div class="form-group">
            <label for="agency">Requestor/Agency</label>
            <input name="agency" type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
        </div>
        <div class="form-group">
            <label for="description">Description of Work:</label>
            <input name="description" type="text" class="form-control" id="agency" placeholder="Description" />
    
        </div>
        <div class="form-group">
            <label for="input-date">Enter Today Date</label>
            <input name="input-date" type="date" value="">
            <span class="result"></span>
        </div>
        <div class="form-group">
            <div class="col-md-10">
                <input id="submit" name="submit" type="submit" class="btn btn-primary">
            </div>
        </div>
    </form>
    

    And then, as @Fred -ii stated in his comment, the php script is wrong:

    echo $POST;
    

    That line is wrong, there is no variable with name $POST before that code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。