-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-ajax.php
33 lines (29 loc) · 866 Bytes
/
add-ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
* Created by PhpStorm.
* User: ET
* Date: 6/13/2015
* Time: 2:20 PM
*/
require_once 'app/init.php';
if (isset($_POST['todoText']))
{
$todoText = htmlentities(trim($_POST['todoText']), ENT_QUOTES);
if (!empty($todoText))
{
$addedQuery = $db->prepare("
INSERT INTO ET_TodoList (todoText, user, done, created)
VALUES (:todoText, :user, 0, NOW())
");
//use array() instead of [] if error happens in servers
$addedQuery->execute(array(
'todoText' => $todoText,
'user' => $_SESSION['user_id']
));
}
// Using PDO's PDO::lastInsertID() to get the last id inserted and then json encode
// so through ajax json value is sent back to the index.php with the proper id
$id = $db->lastInsertId();
$returnValue = array("id"=>$id);
exit(json_encode($returnValue));
}