-3

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

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Sep 28 '15 at 20:28
  • this is a syntax error, for one thing `echo $POST;` and it will throw you an undefined $ variable notice – Funk Forty Niner Sep 28 '15 at 20:28
  • then `name="xxx'` - copy/paste got the best of you. – Funk Forty Niner Sep 28 '15 at 20:29
  • Jay is correct. Use stored procedures - http://www.mysqltutorial.org/introduction-to-sql-stored-procedures.aspx – David P Sep 28 '15 at 20:31
  • 1
    *That's if it even makes it outside the gate Sam* @JayBlanchard – Funk Forty Niner Sep 28 '15 at 20:31
  • 1
    Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 28 '15 at 20:36
  • @DavidP if you think stored procedures are the solution to SQLi, you should really take a look into prepared statements. As a rule of thumb using SP is a bad practice and leads to an unmaintainable system. – Jhuliano Moreno Sep 28 '15 at 20:41

2 Answers2

1

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.

taxicala
  • 21,408
  • 7
  • 37
  • 66
  • Thank you for that snip it, it helped. I did not realize that I had mixed up my quotes. However, I am still getting error for one of the fields Notice: Undefined index: project_name in C:\Program Files (x86)\Ampps\www\gisadmin\admin\insert.php on line 10 How can I find out what's causing this issue? – Teddy Haile Sep 28 '15 at 20:54
  • Yeah check the edit, you are sending the input as name instead of project_name. remember that the name attribute of the input will be the key in the $_POST array. – taxicala Sep 28 '15 at 20:58
  • Yes, I see what you mean. Thank you, that was very helpful and it's working great. – Teddy Haile Sep 28 '15 at 21:03
0

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"