funbinod Posted April 18, 2014 Share Posted April 18, 2014 while trying another method for from validation i encountered error if (isset($_SESSION['error']) && isset($_SESSION['formAttempt'])) { unset($_SESSION['formAttempt']); print "Error(s):<br />n"; foreach ($_SESSION['error'] as $error) { print $error . "<br />n"; } } it returned error: Warning: Invalid argument supplied for foreach() in E:xampphtdocsacpandavinstall.php on line 21 what could be this error! or it could be from action script!? Link to comment Share on other sites More sharing options...
Don E Posted April 18, 2014 Share Posted April 18, 2014 Is what's contained in $_SESSION['error'] suppose to be an array? First argument of foreach is suppose to be the array you want to loop through. Link to comment Share on other sites More sharing options...
funbinod Posted April 19, 2014 Author Share Posted April 19, 2014 following is the line from action script if (isset($_SESSION['error'])) { unset($_SESSION['error']);}$_SESSION['error'] = array();$required = array("company", "address", "user", "pass", "conpass");// check required fieldforeach ($required as $requiredField) { if (!isset($_POST[$requiredField]) || $_POST[$requiredField] == "") { $_SESSION['error'][] = $requiredField . "is required."; }} Link to comment Share on other sites More sharing options...
Don E Posted April 19, 2014 Share Posted April 19, 2014 In the if condition inside the foreach, instead of !isset(), try !empty(). isset doesn't really determine if there is a value or not. All it really means that a variable has been initiated. So for example, if you have: <input type="text" name="username" />$_POST['username'] WILL be set even if it did not have a value entered (assigned) to it. (even if the user did not enter anything in the text box)Using empty() is more helpful in this situation because empty sees if there is anything that indicates a variable is empty, like an empty string '', or false, null, 0, etc. Link to comment Share on other sites More sharing options...
funbinod Posted April 20, 2014 Author Share Posted April 20, 2014 but what i faced the problem is not that. even after changing to !empty the problem remained same.... Warning: Invalid argument supplied for foreach() in E:xampphtdocsacpandavinstall.php on line 21 Link to comment Share on other sites More sharing options...
Don E Posted April 20, 2014 Share Posted April 20, 2014 Are you working with two pages? If so, do you have session_start(); at the very top of your code for both pages? Link to comment Share on other sites More sharing options...
funbinod Posted April 20, 2014 Author Share Posted April 20, 2014 yes i'm working with 2 pages. 'install.php' & 'installprocess.php'. and yes both pages have session_start()........... Link to comment Share on other sites More sharing options...
Ingolme Posted April 20, 2014 Share Posted April 20, 2014 It looks like $_SESSION['error'] is not an array. See what value it has: var_dump($_SESSION['error']); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now