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

2 things: enter doesn't work in IE & empty form
i have this search form that works well except for 2 things.

1) on IE when i hit enter instea

Unable to display contents in Second Drop Down Box
Hi All,

What I am trying to do is 2 dependent drop down boxes and when user selects su

To add a field on the screen XK02.
Hi All,

How to add an additional field in the vendor change control screen XK02.
The

does anyone know a php script to send mail using gmails/googles free smtp server
cause i heard u can do that but i dont know how

"From field" in PHP email form
I used a wizard to create a PHP email form. I was able to customize it with the exception of the Fr

Display certain image depending on time of year
Hi, I am new to these forums and would really appreciate some advice on a piece of coding I have don

Comparing MySql data and arrays.
I have a mysql table set up like this:
idsubjectbodyuseriddatetimetags1blog subjectblog body111|2

comparing tables across databases sql refinement ideas required
Hi all

Via pl/sql I need to ensure that data between tables in different databases match

using file_get_contents??
okay how would i create a script using file_get_contents() in php have it grab search pages 1-20 and

upload image name with extension using php
hi frds..

<input id="file1" type="file" name="file[]" &a

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