I'm new to coding with PHP, and in trying to create a to-do list I have come undone after creating a file called 'add.php' which is supposed to add new data to the table. The main file, index.php, calls the table elements ok and displays them on the browser, but I cannot add new items.
The code in add.php is here:
<?php
require_once 'app/init.php';
if(isset($_POST['name'])) {
$name = trim($POST['name']);
if(!empty($name)) {
$addedQuery = $db->prepare("
INSERT INTO items (name, user, done, created)
VALUES (:name, :user, 0, NOW() )
");
$addedQuery->execute([
'name' => $name,
'user' => $_SESSION['user_id']
]);
}
}
header('location: index.php');
?>
If it helps, I am using PHP 5.5.12 and MySQL 5.6.17, on WampServer 2.5