<?php require_once 'header.php'; require_once 'menubar.php'; require_once '../classes/Task.php'; session_start(); $errorMessage = ""; if (!isset($_SESSION['email'])) { header("Location: home.php"); } else { $userId = $_SESSION['userId']; $email = $_SESSION['email']; $listId = $_GET['list']; if (isset($_POST['addTask'])) { // add new task to DB first, so the list will include it $errorMessage = processAddTask(); } $tasks = Task::getTasksFromDatabase($listId); if (!$tasks) { echo 'Could not get any tasks'; } else { echo "<table border='1'>\n <tr>\n <th>Task name</th>\n <th>Estimation</th>\n </tr>"; // loop through the tasks arrray(contains Task objects) and store each element in task variable foreach ($tasks as $task) { echo "<tr>"; echo "<td>{$task->mTaskName}</td>"; echo "<td>{$task->mEstimation}</td>"; echo "</tr>"; } echo "</table>"; }
<?php require_once 'header.php'; require_once 'menubar.php'; require_once 'userstatus.php'; if (!isset($_SESSION['email'])) { header("Location: start.php"); } if (!isset($_POST['addtask'])) { outputAddTaskForm(""); } else { $errorMessage = processAddTask($conn); if ($errorMessage) { outputAddTaskForm($errorMessage); } else { header("Location: addtasks.php"); } } function processAddTask($connection) { if (empty($_POST['task']) || empty($_POST['time'])) { return "fill all the values"; //return errormessage } else { $email = $_SESSION['email']; $task = $_POST['task']; $time = $_POST['time']; $sqlCommand = "INSERT INTO Tasks (Email, Task, Time) \n VALUES ('{$email}','{$task}','{$time}')"; $result = mysql_query($sqlCommand, $connection); if (!$result) { return mysql_error(); }