I'm having trouble inserting data into a table. Here's the code, pretty straight forward. Yet it always ends up at "could not insert task into tasks table". What I'm I doing wrong? ... // Add Tasks if (isset($_POST['addtask']) && isset($_POST['tasks']) && $_POST['tasks'] == 1) {
//Check for empty fields
if (!empty('task_name') && $_POST['assigned'] != 0 && $_POST['task_type'] != 0) {
// Set vars
$entityid = $_POST['entityid'];
$task_name = $_POST['task_name'];
$task_status = $_POST['task_status'];
$assigned = $_POST['assigned'];
$createdby = $_POST['createdby'];
$tasktype = $_POST['task_type'];
$create_date = $_POST['create_date'];
$due_date = $_POST['due_date'];
$reminder_date = $_POST['reminder_date'];
$task_note = $_POST['task_note'];
// Create date and timestamp
$ctime = mktime(date("H"), date("i"), date("s"));
$cdate = date("H:i:s", $ctime);
// Reformat dates with time
$create_date = $create_date." ".$cdate;
$due_date = $due_date." ".$cdate;
$reminder_date = $reminder_date." ".$cdate;
//DB call
include_once("../inc/db_conn.php");
// db insert for tasks
$sqlinst = "INSERT INTO tasks(`entityid`,`task_name`,`task_status`,`assigned`,`createdby`,`task_type`,`create_date`,`due_ate`,`reminder_date`,`task_note`)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if ($stmt = mysqli_prepare($conn, $sqlinst)) {
//Bind vars to prepend stmt as params
mysqli_stmt_bind_param($stmt, "isiiiissss", $entityid, $task_name, $task_status, $assigned, $createdby, $tasktype, $create_date, $due_date, $reminder_date, $task_note);
mysqli_stmt_execute($stmt);
// Send success msg
header("Location: ../add_task.php?succ=1");
} else {
echo "Could not insert task into tasks table";
die();
}
}
} else {
header("Location: ../index.php");
exit();
}
...
Here is the output of var_dump($_POST) array(12) { ["tasks"]=> string(1) "1" ["entityid"]=> string(1) "0" ["task_name"]=> string(9) "Test Task" ["task_status"]=> string(1) "2" ["assigned"]=> string(1) "4" ["createdby"]=> string(1) "1" ["task_type"]=> string(1) "4" ["create_date"]=> string(10) "2020-08-31" ["due_date"]=> string(10) "2020-09-03" ["reminder_date"]=> string(10) "2020-09-02" ["task_note"]=> string(9) "Test Test" ["addtask"]=> string(0) "" }
2020-08-31 01:58:49
2020-09-03 01:58:49
2020-09-02 01:58:49