TheMathWizard/controllers/notes/create.php
2022-12-20 21:35:05 +01:00

23 lines
643 B
PHP

<?php
require('Validator.php');
$heading = 'Create Note';
$username = 'appUser';
$password = 'password';
$config = require('config.php');
$db = new Database($config['database'], $username, $password);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$errors = [];
if (! Validator::string($_POST['body'], 1, 1000)) {
$errors['body'] = 'A body of no more than 1000 characters is required.';
}
if (empty($errors)) {
$db->query("INSERT INTO notes (body, user_id) VALUES (:body, :user_id)", [
'body' => $_POST['body'],
'user_id' => 1
]);
}
}
require 'views/notes/create.view.php';