NickG21 Posted January 5, 2007 Share Posted January 5, 2007 hey everyone,i have multiple form pages that are storing all of the variables using[code]<?php session_start(); foreach($_POST as $key => $var) { $_SESSION[$key] = $var; } ?>[/code]I was wondering if anyone could give me an idea of a Loop that could go through these variables as soon as the "next" or "submit" buttons are pressed and just check to make sure none of them are empty? Quote Link to comment Share on other sites More sharing options...
psychohagis Posted January 5, 2007 Share Posted January 5, 2007 well surely you could do this on the page they are sent to so: [code]If ($_POST['whatever']='' or $_POST['whatever']='' or $_POST['whatever']''){echo echo '<meta http-equiv=refresh content=0;URL=http://www.YOURSITE.COM/YOURPAGE.php?error=some or all fields were left blank>';}[/code] Quote Link to comment Share on other sites More sharing options...
taith Posted January 5, 2007 Share Posted January 5, 2007 [code]<?phpsession_start();foreach($_POST as $key => $var){ if(!empty($_SESSION[$var])) $_SESSION[$key] = $var; else $empty[]=$key;}?>[/code]there ya got an array of all the empty $_POST's Quote Link to comment Share on other sites More sharing options...
NickG21 Posted January 5, 2007 Author Share Posted January 5, 2007 Warning: Illegal offset type in /home/web/.../headerImage.php on line 4Warning: Illegal offset type in /home/web/.../headerImage.php on line 4[code]<?phpsession_start(); foreach($_POST as $key => $var){ if(!empty($_SESSION[$var])) $_SESSION[$key] = $var; else $empty[] = $key;}echo $empty;?>[/code]that is the code that i put in and that is the error i get. if anyone knows any tutorials that would allow me to just do error checking and be able to have someone return back to the previous page to fix them that would be great too and i wouldn't waste people's time with these questions i just can't seem to find a good one yet Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 5, 2007 Share Posted January 5, 2007 This line:[code]<?phpif(!empty($_SESSION[$var])) $_SESSION[$key] = $var;?>[/code]should read[code]<?phpif(!empty($var)) $_SESSION[$key] = $var;?>[/code]And if you just say "echo $empty", you will get a line saying "Array", use:[code]<?phpecho '<pre>' . print_r($empty,true) . '</pre>';?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.