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? Link to comment https://forums.phpfreaks.com/topic/33005-checking-empty-session-variables/ 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] Link to comment https://forums.phpfreaks.com/topic/33005-checking-empty-session-variables/#findComment-153669 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 Link to comment https://forums.phpfreaks.com/topic/33005-checking-empty-session-variables/#findComment-153671 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 Link to comment https://forums.phpfreaks.com/topic/33005-checking-empty-session-variables/#findComment-153682 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 Link to comment https://forums.phpfreaks.com/topic/33005-checking-empty-session-variables/#findComment-153700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.