storing results of a function - previous result overwritten with new result


Posted on 16th Feb 2014 07:03 pm by admin

I have created a function to validate input.

function validate_dimension($value,$name) {

global $errors;
$errors = array();

......validation actions here - this all works fine - if I get an error it is captured like this . . .

$errors[] = "Dimension value missing";

This is all fine and the $error is returned correctly.

So that I can keep the error, I save it as a Session variable

$_SESSION['errors'] = $errors;

HOWEVER the next time I run the function (with the next dimension to be checked) , $_SESSION['errors'] is overwritten and the first error is lost.

I have solved the problem by creating a new array - $all_errors - and adding $errors to $all_errors each time the function is run - but this seems clumsy - I do not need the function as I could just as easily wite a separate line of code for each dimension to be checked.

Can anyone suggest a better way of doing this?
Please?

No comments posted yet

Your Answer:

Login to answer
205 Like 31 Dislike
Previous forums Next forums
Other forums

Staff Induction System - No idea where to go from here!!!
Hi there, I'm pretty new to PHP and Mysql so could really do with being pointed in the right directi

CE 7.1 and External GIS integration
Hi All,

We want to develop an application on CE 7.1 which uses GIS features from an exter

Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there

Logging and nologging bulk insert
Hi,

oracle version: 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production

Table sorting
Hi,

I'm trying to modify the following in order to make the output table sorted alphabeticall

Problem with HTTP Caching...?
Hi there, im trying to implement caching. But it doesn't always work.
I post it here because ther

php ajax - two drop down list with a submit button
i have created a form with 2 drop-down list and a submit button. I would like to know how to pass th

Move array index to end
Hey guys,
Quick question:

I have an array that looks like this:
Code: [Select]$var =

Need to write a cookie with a url var
Not sure if its possible, but I need to write a cookie with a url.

So this would write 2232 a

get the country of visitor and display content based on that
Hello all,

I have seen that Google analytics can tell you where a visitor is coming from and

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash