joshim5
joshim5

Reputation: 2255

PHP & MySQL INSERT INTO problem

Any ideas why the following code is not adding anything into the database once the user fills out the form? I'd really appreciate it.

Thank you!

    if($_SESSION['loginSuccess']==1) {

        // ============================================================
        // = Create the table of current tasks stored in the database =
        // ============================================================
        $userID = $_SESSION['userID'];
        $result = mysql_query("SELECT * FROM Tasks WHERE userID = '$userID'");
        echo "<div id=\"draggable\" class=\"ui-widget-content\"><table border='5'><tr class=\"ui-widget-header\"><td><u>Task Name:</u></td><td><u>Class:</u></td><td><u>Due Date:</u></td><td><u>Task Type:</u></td></tr>";
        echo $_SESSION['userID'];
        while($row = mysql_fetch_array($result)) {
            $taskName = $row[1];

            $class = $row[2];

            $taskDueDate = $row[3];

            $taskType = $row[4];


            echo "<tr><td>'$taskName'</td><td>'$class'</td><td>'$taskDueDate'</td><td>'$taskType'</td></tr>";
        }
        echo "</table>";

        function addNewTask ($name, $class, $dueDate, $type) {
            mysql_query("INSERT INTO Tasks VALUES ('$userID','$name', '$class', '$dueDate', '$type')");
        }

    if($_POST['taskName'] != NULL) {
            addNewTask($_POST['taskName'], $_POST['class'], $_POST['dueDate'], $_POST['dueDate']);
        }

?>


<!-- <img border="1" alt="New" src="/newTask.png" id="newTask" onmouseClick="showTaskField"/> -->
<p><form name="newTask" method="post" action="index.php" id="newTask"><br>
    Task Name: <input name="taskName" type="text"> (necessary)<br>
    Class: <input name="class" type="text"><Br>
    Due Date: <input name="dueDate" type="text" id="datepicker"><Br>
    Type: 
    <input type="submit"></p></div>

Upvotes: 3

Views: 1632

Answers (1)

Galen
Galen

Reputation: 30170

Try getting rid of the ' around the variables in the insert statement. If that does nothing echoing mysql_error().

Upvotes: 4

Related Questions