<?php session_start(); if (!isset($_SESSION["user_id"])) { header('Location: login.php'); die; } if (isset($_GET['todo_id'])) { include_once 'TodoDb.php'; $db_access = new TodoDb(); if ($db_access->deleteTodoItem($_SESSION['user_id'], $_GET['todo_id'])) { header('Location: list.php'); die; } else { header('Location: list.php'); die; } } else { header('Location: list.php'); die; }
<?php if (isset($_POST['username'])) { $username = htmlspecialchars($_POST['username']); $password = htmlspecialchars($_POST['password']); include_once "TodoDb.php"; $db_access = new TodoDb(); $errorMessage = null; $registrationResult = $db_access->createUser($username, $password); if ($registrationResult === true) { header('Location: login.php'); die; } else { $errorMessage = $registrationResult; } } include_once 'partials/header.php'; ?> <body> <?php if (isset($errorMessage)) { ?> <h2>Error: <?php echo $errorMessage['message']; ?> </h2> <?php } ?> <h1>Register:</h1>
<?php session_start(); if (!isset($_SESSION["user_id"])) { header('Location: login.php'); die; } if (isset($_POST['todo_text'])) { include_once 'TodoDb.php'; $db_access = new TodoDb(); if ($db_access->addTodoItem($_SESSION['user_id'], $_POST['todo_text'])) { header('Location: list.php'); die; } else { header('Location: list.php'); die; } } else { header('Location: list.php'); die; }
<?php if (isset($_POST['username'])) { $username = htmlspecialchars($_POST['username']); $password = htmlspecialchars($_POST['password']); include_once 'TodoDb.php'; $db_access = new TodoDb(); $isValid = $db_access->isUserValid($username, $password); if ($isValid != false) { session_start(); $_SESSION['username'] = $isValid['username']; $_SESSION['user_id'] = $isValid['user_id']; header('Location: list.php'); die; } $errorMsg = 'Invalid login.'; } include_once 'partials/header.php'; ?> <body> <?php if (isset($errorMsg)) { ?> <h2>Error: <?php echo $errorMsg; ?> </h2> <?php } ?>
<?php session_start(); if (!isset($_SESSION["user_id"])) { header('Location: login.php'); die; } include_once 'TodoDb.php'; $db_access = new TodoDb(); $todos = $db_access->getTodoItems($_SESSION['user_id']); $todosView = ""; foreach ($todos as $todo) { $todosView .= '<li class="ui-state-default">' . $todo['todo_item'] . '<form method="get" action="delete.php"><input name="todo_id" type="hidden" value="' . $todo['id'] . '"/><input type="submit" class="btn btn-danger" value="X" /></form></li>'; } include_once 'partials/header.php'; ?> <body> <div class="container"> <div class="row"> <div class="col-md-6"> <div class="todolist not-done"> <h1>Todos</h1> <form action="add.php" method="post"> <input type="text" class="form-control" name="todo_text"> <input type="submit" class="btn btn-default form-control" value="Add todo"> </form> <hr> <ul class="list-unstyled text-center"> <?php echo $todosView;
public static function setInstance($user, $pass, $dbName, $host) { if (self::$inst == null) { self::$inst = new self($user, $pass, $dbName, $host); } }