Jump to content

Recommended Posts

New guy here, having an issue with what I imagine is an unusual script.

 

I've got a form that posts to session variables.  Every part of the form is required so I was hoping to save time validating/passing an error back for every iteration, so I decided to try having the script create its own variables.  So the first part goes through each Session variable and checks for value.  If it has a value of 0 or false, it tries to create a session variable of the same name but with an "error_" prefix to pass back.  Then on the original form page when it bounces back (script not shown) each form element with missing values can simply use the newly created variable to set their very own red-pink error background. 

There are probably better ways to do this, and I'm open to suggestions, but practical or no - I think this should work.

 

The problem is it doesn't work, and I'm not sure why.  When I run the script through ZendStudio, it gives me this error (processes and displays everything up until that point):

 

Fatal error: Allowed memory size of 18874368 bytes exhausted (tried to allocate 3776 bytes) in path/validation.php on line 36

 

When I see it from a browser, it shows everything up until that point but doesn't show that error - just seems to cack out there.

 

 

Here's the script pertinent to the problem.

 

foreach($_SESSION as $var=> $value)
{
if ($var<1)
{
	$_SESSION["error_$var"]='style="background-color:#FFD8D9;"';
}
}

 

Thanks for the help!

ok i figured out part of the problem.  the "=> $value" part was unnecessary for what i was doing (I think) so i removed it.  The revised script has new behavior but still not what I was hoping for.

 

foreach($_SESSION as $var)
{
if (empty($var))
{
	$temp="error_$var";
	$_SESSION[$temp]='style="background-color:#FFD8D9;"';
	#$_SESSION["error_$var"]=
}
}

 

produces this and stops without looping over anything else:

 

error_=>style="background-color:#FFD8D9;"

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.