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 trialAlex Gwartney
13,256 PointsUnable to redirect after using create method.
I'm not sure if its me or there is a bug someplace that Im just overlooking. The code below I have gone over several times and for some reason the if statement that has the header redirect never gets called after adding the value to the database. Its weird because I can add the values without a problem but for some reason, it continues to just populate the error message created.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$title = trim(filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING));
$category = trim(filter_input(INPUT_POST, 'category', FILTER_SANITIZE_STRING));
if (empty($title) || empty($category)) {
$error_message = 'Please fill in the required fields: Title, Category';
} else {
if (add_project($title, $category)) {
header('Location: project_list.php');
exit;
} else {
$error_message = 'Could not add project';
}
}
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Alex Gwartney! It would be interesting to see the add_project
function in its entirety. The only reason I can think that wouldn't work is for some reason the add_project
function is returning a falsey value.
Looking forward to hearing back!
Alex Gwartney
13,256 PointsAlex Gwartney
13,256 PointsHi Jennifer,
I actually figured it out it had to do with the function returning false. I had missed where I was returning in the add project function.