PDA

Click to See Complete Forum and Search --> : checking session vars


chrisjk
Mar 13th, 2002, 07:08 PM
I'm trying to do some validation with form data passed to a script and stored in session vars, but not getting very far

I have an array of session var names I want to check to make sure they aren't empty$req_vars = array("field1", "field2", "field3");How can I get PHP to check each of those fields ensuring each has a value? This has really got me stumped. I'm using the $_SESSION thing BTW

Thanks

scoutt
Mar 14th, 2002, 03:06 PM
if (($req_var[0] = "") || ($req_var[1] = "") || ($req_var[2] = "") ){
then do what you want...

}

wouldn't that work?

chrisjk
Mar 14th, 2002, 03:10 PM
I don't think so since that would check $req_var[0] to see if it's empty rather than $req_var[0]'s value (being "field1")

Not as easy as it looks methinks

scoutt
Mar 14th, 2002, 04:10 PM
so field1 is the variable name in the session too?

well, for whatever the name of the session variable is can't you just do this.

if (session_registered(field1)) {



maybe I am confused here. what is the name of the session variable that is suppose to be in the session.

chrisjk
Mar 14th, 2002, 04:24 PM
I solved it by forgetting the array of names and just checking them each manually.

Tedious but works, thanks anyways :cool: