I'm not very good with php or mysql so I can't figure out what I'm doing wrong.

I get this error: Failed You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'tests,'20120508,'5.5,'20120508)' at line 1

I'm using WAMP. MySQL 5.5.16 and PHP 5.3.8

The following is my script.

<html>
<head>
<style type="text/css"> 
body{
background-color: #000;
font-family: "Arial";
color: #fff;
}

#mainwrapper{
width: 1024px;
background-color: #a1a1a1;
margin-left:auto;
margin-right:auto;
padding: 5px;
}

</style>
</head>
<body>
<div id="mainwrapper">
  <form name="projectEnter" method="post" action="includes/progress-form.php">
    <table width="800" border="0">
      <tr>
        <td>Project Name</td>
        <td><label for="projectName"></label>
        <input type="text" name="projectName" id="projectName"></td>
      </tr>
      <tr>
        <td>Date Started (YYYY-MM-DD)</td>
        <td><label for="dateStarted"></label>
        <input type="text" name="dateStarted" id="dateStarted"></td>
      </tr>
      <tr>
        <td>Completion Estimation</td>
        <td><label for="completeEstimation"></label>
        <input type="text" name="completeEstimation" id="completeEstimation"></td>
      </tr>
      <tr>
        <td>Date Closed (YYYY-MM-DD)</td>
        <td><label for="dateClosed"></label>
        <input type="text" name="dateClosed" id="dateClosed"></td>
      </tr>
    </table>
    <input type="submit" name="submit" id="submit" value="Submit">
  </form>
</div>
</body>
</html>

USER and PASS both have the correct user information. Just didn't want to post it here.

<?php
    $conn = mysql_connect("localhost","USER","PASS");
    $db = mysql_select_db("project_progress",$conn);
?>

<?php
    # Variables for field names.
    $_projectName = $_POST['projectName'];
    $_dateStarted = $_POST['dateStarted'];
    $_completeEstimation = $_POST['completeEstimation'];
    $_dateClosed = $_POST['dateClosed'];

    # Inserting information into table.
    $sql = "INSERT INTO progress values(".$_projectName.",'".$_dateStarted.",'".$_completeEstimation.",'".$_dateClosed.")";
    $query = mysql_query($sql);

    if (!$query) {
      echo "Failed " .mysql_error();
    } else {
      echo "Data entered ";
    }

?>

projectName is varchar(50)
dateStarted is date
completeEstimation is float
dateClosed is date

I want to put validation in my script too, but right now I'm just trying to get it to insert into the table.

Re: Posting data to a database table using a PHP script 80 80

You can see your mistake in the error message. Pay close attention to the quotes and you'll see you aren't placing them in the correct positions.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'tests,'20120508,'5.5,'20120508)' at line 1

You have (Test, '20120508, '5.5, '20120508). You missed the closing quote in three places.

Re: Posting data to a database table using a PHP script 80 80

Thanks for the heads up. I ended up changing this line:

$sql = "INSERT INTO progress (projectName,dateStarted,completeEstimation,dateClosed) VALUES ('$_projectName','$_dateStarted','$_completeEstimation','$_dateClosed')";

Concantenating is apparently too advanced for me at the moment. :P

Thanks again for the help, I'm sure I'll be back asking more stupid questions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.