Forum Moderators: coopster

Message Too Old, No Replies

Assign New Values to HTTP_POST_VARS

         

phparion

6:07 pm on Jan 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi
I have a form that post 9 variables to a page, in action page i want to assign "OPTIONAL" as value to all variables which are posted Blank, for example if Salary field is posted Blank then assign it word "Optional" and then use it to insert into database so that in database insteasd of blank it will contain "Optional"

I have done the following coding.

PHP Code:
$spitter=$HTTP_POST_VARS;

foreach($spitter as $op=>$val) {

if ($val=="")
$val="Optoinal";
}

foreach ($HTTP_POST_VARS as $temp =>$sub) {
$sub = $temp->$val;
}

the first part of the code is working, but when i again assign new values to HTTP_POST_VARS array its not working, and not taking the new values, i want assign new values from array SPITTER to HTTP_POST_VARS so that in further code i can use HTTP_POST_VARS to insert data into table.

pleas guide me about this.

Thanks

dmorison

6:27 pm on Jan 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're not actually assigning new values at all, which is why it is not working.

When you use foreach( $array as $key => $value), the $key and $value as visible to your loop are new variables; they are not "pointers" or references to the original array.

What you need to do is re-populate $HTTP_POST_VARS using the $key component, something like this:


foreach($spitter as $op=>$val)
{
if ($val=="") $HTTP_POST_VARS[$op] = "Optoinal";
}

phparion

8:26 pm on Jan 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



it worked perfectly , thank you very much