Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Pontus Bolmér
Pontus Bolmér
12,471 Points

Header wont relocate...

Ok im doing this crud operations...Everything works fine..But my Header location wont relocate me to to the right task...

function add_task($project_id, $title, $date, $time) { include 'connection.php';

$sql = 'INSERT INTO tasks(project_id, title, date, time) VALUES(? , ? , ? , ?)';

try{ $results = $db->prepare($sql); $results->bindValue(1, $project_id, PDO::PARAM_INT); $results->bindValue(2, $title, PDO::PARAM_STR); $results->bindValue(3, $date, PDO::PARAM_STR); $results->bindValue(4, $time, PDO::PARAM_INT); $results->execute(); } catch(Exception $e) { echo "Error!: ". $e->getMessage(); return false; } return true; }

the function

then the redirect wont work... I have tried everything It should take me to task_list.php

if($_SERVER['REQUEST_METHOD'] == 'POST') { $project_id = trim (filter_input(INPUT_POST, 'title', FILTER_SANITIZE_NUMBER_INT)); $title = trim (filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING)); $date = trim (filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING)); $time = trim(filter_input(INPUT_POST, 'category', FILTER_SANITIZE_NUMBER_INT));

if(empty($project_id) || empty($title) || empty($date) || empty($time)) { $error_message = "Please fill in the required fields: Project, Title, Date and Time"; } else { if(add_task($project_id, $title, $date, $time)) { header('Location: task_list.php'); exit; } else { $error_message = "Could not add task"; } } }

1 Answer

Hello, did you try header('Location: http://<path to>/task_list.php')

Pontus Bolmér
Pontus Bolmér
12,471 Points

Yes i have, and that should not mather, since im doing the same thing with adding projects.