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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dopa53272 2015-09-28 20:33

    Are you getting success message but database is not getting updated OR Getting Total Error...???

    1) Check for double quotes and single quotes..

      <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> 
    

    2) Also check for path... for

    include("../includes/config.php");
    

    Is it correct or not...?

    3)

    <label for="project_name">Project Name</label> 
    <input name="name' type="text" 
    

    SHOULD BE

     <label for="project_name">Project Name</label>
     <input name="project_name" type="text" 
    
    评论
    解决 无用
    打赏 举报