was racking my brain for the last 2 days wondering why my code didnt work. basically tested and removed blocks till I realised that ONLY if i remove the header and return lines in my fn, the $_SESSION['errormsg'] sets and can be echoed later. So my question is why does the header redirect make it not work when i later call for echo $_SESSION['errormsg']? thanks! sorry am quite new still!
function accountCreate($username) { if(( strlen($username) < 1 )) { $_SESSION['errormsg'] = 'Please fill out all fields.'; header ('location: accountcreate.php'); return; }}
main index.php:
<?phprequire_once "pdo.php";require_once "php-accounthandling.php";require_once "php-formhandling.php";require_once "php-messagedisplay.php";session_start();//redir if logged in (dlted to test)//validate and insert form dataif (isset($_POST['create'])) { accountCreate($_POST['username']);}?><!DOCTYPE html>...<?php displayMessage(); ?>
Tried asking chatGPT, tried a couple discord groups, still don't understand. One answer said that I should check my error_log in case i am outputting before the header, but doubt this it the case, and my error_log is clean.