Changing $variables based on a webform

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Changing $variables based on a webform

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Changing $variables based on a webform

Post by requinix »

markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Re: Changing $variables based on a webform

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Changing $variables based on a webform

Post by Benjamin »

It's probably 2 paragraphs of text. The rest of the page is filled with comments.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Changing $variables based on a webform

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Re: Changing $variables based on a webform

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Changing $variables based on a webform

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Re: Changing $variables based on a webform

Post by markosjal »

AbraCadaver

Thanks, I am looking into those,
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Changing $variables based on a webform

Post 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.
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Re: Changing $variables based on a webform

Post 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
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: Changing $variables based on a webform

Post 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
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Re: Changing $variables based on a webform

Post by markosjal »

How would I write it back to the file?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Changing $variables based on a webform

Post by AbraCadaver »

markosjal wrote:How would I write it back to the file?
file_put_contents() maybe?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply