//Check if the forms are blank if(($myusername=="") || ($mypassword=="")){ header("Location:index.php"); }else{ } PHP: My problem is, when one of the forms are blank, how would i display and error message on the homepage? cookies?sessions? is there any other options besides those? because they get messy... not to mention that i also have to unset after.. thx
You can pass a parameter to your index.php in the location line, for example: header("Location: index.php?error=1"); and in the index file just check for it: if (isset($_GET['error'])) { echo 'one of the fields is blank'; }
What mulari suggested is the quickest, easiest way of doing it. A slightly more involved but useful method to consider is using "flash data." Essentially, it is data stored in the session only until the next request and is very typical for errors or status update (e.g., "Record X deleted").