Part on Form validation finished
This commit is contained in:
parent
a597943b45
commit
ef90228439
2 changed files with 32 additions and 5 deletions
|
|
@ -5,7 +5,21 @@ $password = 'password';
|
|||
$config = require('config.php');
|
||||
$db = new Database($config['database'], $username, $password);
|
||||
|
||||
if($_SERVER['REQUEST_METHOD'] === 'POST'){
|
||||
$db->query("INSERT INTO notes (body, user_id) VALUES (:body, :user_id)", ['body' => $_POST['body'], 'user_id' => 1]);
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$errors = [];
|
||||
|
||||
if (strlen($_POST['body'] === 0)) {
|
||||
$errors['body'] = 'A body is required.';
|
||||
}
|
||||
if (strlen($_POST['body'] > 1000)) {
|
||||
$errors['body'] = 'The body cann not be more than 1000 characters.';
|
||||
}
|
||||
if (empty($errors)) {
|
||||
|
||||
$db->query("INSERT INTO notes (body, user_id) VALUES (:body, :user_id)", [
|
||||
'body' => $_POST['body'],
|
||||
'user_id' => 1
|
||||
]);
|
||||
}
|
||||
}
|
||||
require 'views/note-create.view.php';
|
||||
require 'views/note-create.view.php';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue