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

Sum of Values in an Array
This is probably really simple... but it's been years since I've written anything, so bare with me!<

$get problem
Hi Guys ...

can you please tell me what i am doing wrong here
Code: <?php

Help with file_get_html
The following code gives the expected results:

<html>
<head&g

Re-Order by ID Number
I have a cms set up for inputting an image, thumb, title, pdf, and eps. When input the database ass

file downloaded can't be read !!
<?php
$fileName = 'mypic.jpg';
$mimeType = 'image/jpeg';
header('content-dispositio

Curl timeout breaks script
So im having difficulties with skipping timeout error in curl
my script calls different functions

newbie question
Hi out thereIm totaly new in this forum and to .net and vb so here is a totaly newbie question.I wan

array help
Does anyone know how to require 10 text fields for individual grades and output class average? (10 p

Dynamic Array using glob?
Is there an easier way to do this?

I am trying to get create a dyamic array based on files wi

Parse error: syntax error, unexpected $end in
hello,
i receive the error :Parse error: syntax error, unexpected $end in C:xamppxampphtdocsh

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