Lamez Posted December 20, 2009 Share Posted December 20, 2009 Okay so what I am trying to do is call a certain value out of an array, which is stored in a $_SESSION variable (which is also an array). The array in question is my errorArray, and in the registration process, if an error occurs, I add the error to the errorArray. That part works just fine, it is just getting the value out. Here is what I have so far: <?php function getError($field){ return $_SESSION['errorArray'][$field]; } //example echo getError("email"); ?> This returns nothing. Any ideas? -Thanks! (again.) Quote Link to comment Share on other sites More sharing options...
printf Posted December 20, 2009 Share Posted December 20, 2009 I don't see any session_start(); in your script. Evey page must have session_start() before trying to use the SUPER GLOBAL $_SESSION! <?php session_start (); function getError($field){ return $_SESSION['errorArray'][$field]; } //example echo getError("email"); ?> p! Quote Link to comment Share on other sites More sharing options...
Lamez Posted December 20, 2009 Author Share Posted December 20, 2009 that is a snippet of the code. You don't want the whole code. Quote Link to comment Share on other sites More sharing options...
Catfish Posted December 20, 2009 Share Posted December 20, 2009 if it's returning nothing, then $_SESSION['errorArray']['email'] is empty. Checked your spelling/case sensitivity? Quote Link to comment Share on other sites More sharing options...
Lamez Posted December 20, 2009 Author Share Posted December 20, 2009 Question, does this look right? array(6) { [0]=> array(1) { ["email"]=> string(21) "Email field is empty." } [1]=> array(1) { ["email2"]=> string(21) "Email field is empty." } [2]=> array(1) { ["pass"]=> string(24) "Password field is empty." } [3]=> array(1) { ["pass2"]=> string(24) "Password field is empty." } [4]=> array(1) { ["first"]=> string(20) "First name is empty." } [5]=> array(1) { ["last"]=> string(19) "Last name is empty." } } I did this to get that information: <?php var_dump($_SESSION['errorArray']); ?> Here is the function that adds the values to the array <?php function addError($field, $error){ if(!array_key_exists($field, $error)){ $_SESSION['errorArray'][] = array($field => $error); } } ?> Does all that look right to you guys? Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 20, 2009 Share Posted December 20, 2009 Your error starting function. function addError($field, $error){ if(!array_key_exists($field, $error)){ $_SESSION['errorArray'][] = array($field => $error); } } is assigning the errors to the next available space in the errorArray. For your retrieval function to work as you expect your starting code should be something like this.. function addError($field, $error){ $_SESSION['errorArray'][$field] = $error; } Quote Link to comment Share on other sites More sharing options...
Lamez Posted December 20, 2009 Author Share Posted December 20, 2009 Thank you so much, that fixed everything! I am new to arrays, and the manual did not solve my problems. Thanks again! 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.