Friday, 26 February 2016

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

echo $_SESSION['userID'];
while($row = mysql_fetch_array($result)) {
$taskName = $row[1];

$class = $row[2];

$taskDueDate = $row[3];

$taskType = $row[4];



echo "";
}
echo "
Task Name:Class:Due Date:Task Type:
'$taskName''$class''$taskDueDate''$taskType'
";

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']);
}

?>




Task Name: (necessary)
Class:

Due Date:
Type:



Answer



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


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...