Page 1 of 1
Changing $variables based on a webform
Posted: Mon Jun 14, 2010 1:19 pm
by markosjal
I have $variables defined in a config file
I want to be able to modify those variables based on a selection or text entered from a webform.
For instance if a selection is made for active or inactive a varoiable is changed from 0 to 1
or if a 10 is entered (input), the $num=(input) will then be changed in the config file where the $num variable is defined .
I hope this is clear enough, any help appreciated.
Thanks
Mark
Re: Changing $variables based on a webform
Posted: Mon Jun 14, 2010 1:27 pm
by requinix
Re: Changing $variables based on a webform
Posted: Mon Jun 14, 2010 2:28 pm
by markosjal
Thank for the tip, however that is a lot of reading and seems to be of little relevance.
I am mostly concerned with how to write the variable to the correct line of the file.
Any othe suggestion how to painlessly accomplish this?
Any samples?
Re: Changing $variables based on a webform
Posted: Mon Jun 14, 2010 2:33 pm
by Benjamin
It's probably 2 paragraphs of text. The rest of the page is filled with comments.
Re: Changing $variables based on a webform
Posted: Mon Jun 14, 2010 2:47 pm
by AbraCadaver
It doesn't seem relevant to what they are asking about.
I have used a combination of include(), var_export() and file_put_contents() for this.
Re: Changing $variables based on a webform
Posted: Mon Jun 14, 2010 2:57 pm
by markosjal
Perhaps I should clarify...
My concern is HOW to read/write that variable to/from the file. In other words locating the line, and writing its value correctly in place.
Then page referenced seemed that someone thought I wanted to know how to make a webform , and that is not the case.
THanks
Mark
Re: Changing $variables based on a webform
Posted: Mon Jun 14, 2010 3:17 pm
by AbraCadaver
I gave you the functions. I would also suggest using an array in the config file to make it easier to work with.
You could also serialize the array and save it in the config file.
Re: Changing $variables based on a webform
Posted: Mon Jun 14, 2010 4:42 pm
by markosjal
AbraCadaver
Thanks, I am looking into those,
Re: Changing $variables based on a webform
Posted: Mon Jun 14, 2010 7:42 pm
by JakeJ
Would it perhaps be easier just to put those variables in to a different php page and then use an include? If those variable will rarely change, it might be a lot easier and not very difficult to maintain it as long as you document in both files what's going on.
Then again, if something else is constantly changing that config file, nevermind.
Re: Changing $variables based on a webform
Posted: Wed Jun 16, 2010 1:32 am
by markosjal
this project is an admin interface for some display ads.
My goal is to have them manipulated ONLY from the admin interface, but HARD written into the files .
thanks
Mark
Re: Changing $variables based on a webform
Posted: Wed Jun 16, 2010 6:40 am
by Phoenixheart
From top of my head (If I got your question right):
Example you have 3 variables: $a, $b, $c. You'll write into the config file like this:
Code: Select all
$vars = array(
'a' => $a,
'b' => $b,
'c' => $c,
);
$vars = serialize($vars); // here you serialize the array into a string
file_put_contents('config.inc', $vars); // and write it into the config file
Then, to turn it back into variables:
Code: Select all
$vars = file_get_content('config.inc');
$vars = unserialize($vars); // turn it into the array
extract($vars); // after this you'll have $a, $b, $c ready to rock
Re: Changing $variables based on a webform
Posted: Tue Jun 22, 2010 3:29 pm
by markosjal
How would I write it back to the file?
Re: Changing $variables based on a webform
Posted: Tue Jun 22, 2010 3:34 pm
by AbraCadaver
markosjal wrote:How would I write it back to the file?
file_put_contents() maybe?