"Dave Smithz" <SPAM FREE WORLD> wrote:
[color=blue]
> I have a php script that does some form input validation. As it
> verifies each field if the field has incorrect data, it appends an
> error message to an $error array. E.g.
>
> if (an_error = true) {
> $errors.="<tr><td>You have note entered a surname. This is
> mandatory date
> of birth incorrectly.</td></tr>";
> }[/color]
This looks like a string not an array.
[color=blue]
> Previously I had always had the HTML error page code contained within
> the same script, but now I am moving it out to make maintenance
> easier.
>
> When validation completes there is now a statement that says
> if ($errors!="") {
> header("Location: ./error_page.php");
> }
>
> However, how can I pass the errors array to the error_page. I want to
> be able to list each error individually.
>
> Forgive me if this is a silly easy question. I have only been doing
> PHP for about a week.
> Thanks in advance.[/color]
Assuming it is actually an array, you can loop through it along the
lines of something like so:
$vars = '?';
for($i = 0; $i < sizeof($array); $i++) {
$vars .= "array[]=" . urlencode($array[$i]) . '&';
}
Then the receiving page will have an array $_GET['array'] filled with
elements.
If it's an associative array you can do this:
$vars = '?';
foreach($array as $name => $value) {
$vars .= $name . '=' . urlencode($value) . '&';
}
You can also use the serialize and unserialize functions to turn the
array into a string which you would then use urlencode make it url
safe.
Functions in the manual online here:
http://www.php.net/urlencode http://www.php.net/serialize http://www.php.net/unserialize http://www.php.net/foreach
--
Chris Hope - The Electric Toolbox -
http://www.electrictoolbox.com/