-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddListProcess.php
52 lines (42 loc) · 1.54 KB
/
addListProcess.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
//NOTE - all commented out 'echo' statements are for debugging, but have been removed to allow for the appropriate redirect AT THE END of the process
session_start();
error_reporting(E_ALL);
ini_set(“display_errors”, 1);
?>
<?php
//echo '<p>You have just created a list: '.$_POST['listName'].'</p>';
//Create database
require 'database.php';
$db = new Database();
//Adding new list
require "security.php";
$string = h($_POST['listName']);
$stmt = $db->prepare("INSERT INTO lists (name) VALUES (:ln);");
$stmt->bindValue(":ln", $string, SQLITE3_TEXT);
//echo 'Executing: '.$sql.' ...<br>';
$stmt->execute();
//echo 'Success<br><br>';
//Retrieving the corresponding listID:
$listID = $db->lastInsertRowID();
/*
echo '<p>listID: '.$listID.'</p>';
echo 'Session: ';
foreach($_SESSION as $item) {
echo $item;
}
echo '<br>';
*/
//Ensuring relation is established between this new list ^, and the user that created it
$stmt = $db->prepare("INSERT INTO listRel(userID, listID, perm) VALUES (:uid, :lid, 0);");
$stmt->bindValue(":uid", $_SESSION['uid'], SQLITE3_INTEGER);
$stmt->bindValue(":lid", $listID, SQLITE3_INTEGER);
//var_dump($sql);
//echo 'Executing: '.$sql.' ...<br>';
$stmt->execute();
//echo 'Success<br><br>';
//echo '<br><br><br><hr><p>...ALL Completed successfully</p>';
header('Location: '.$_SERVER['HTTTP_HOST'].'list.php?lid='.$listID, 303);
//This causes the script to redirect to the specified URL (with 303='see other'), however the script continues to run in the background, ehcne it is terminated with 'exit()' below.
exit();
?>