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) {

Did you know?Explore Trending and Topic pages for more stories like this.
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

Add weeks in a query?
I have a SQL that summarizes the quantity per week. The weeks that has no value does not exist in th

FAGL_FC_TRANSLATION FAS52 New GL ECC 6.0
Hello,

The new program for Translating GL Balances (FAS 52) gives the option to use diffe

Preg_match with an array
is there an away to use preg_match with an array?

i want to check a string with an array to s

Php mysql - select?
Hi i have this code:
Code: $iteminfo = mysql_query("SELECT desc FROM wc_items WHERE itemid =

Syntax error
hi im having a little trobble with this script
-------------------------------------------------

list files from folder, only one for each date
I have many files in a folder and wish to only list one of each date

these are the file names

Sessions Value Not Saved
Hi,

Im making a login form and im using this code:
Code: if($login=="true"){

How to make a mail Form secure?
I want to create an email Form on my web site. How can I make the Form secure so the submitted info

SCRIPT ERROR
Here is the CONTACT FORM I made for our website:

<form id="form1" name="

Different actions for different parts of a string
<?php
function dosomething($string, $else = '') {
if (empty($else))
$string

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