Current location: Hot Scripts Forums » Programming Languages » PHP » Writing from form to php config file


Writing from form to php config file

Reply
  #1 (permalink)  
Old 04-22-04, 12:54 PM
Squid44th Squid44th is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Writing from form to php config file

What I would like to do is open my site.config.php file and relplace some of the variables with ones that are gathered in a preferences form.

Example,

site.config.php reads:
<?
DEFINE ("COMPANY_NAME", "Your Company Name");
DEFINE ("COMPANY_ADDRESS", "123 Main Street");
DEFINE ("COMPANY_CITY", "Anytown");
DEFINE ("COMPANY_STATE", "NV");
DEFINE ("COMPANY_ZIP", "99999");
// database settings
DEFINE ("DB_HOST", "localhost");
DEFINE ("DB_NAME", "clientloginutility");
DEFINE ("DB_USER", "root");
DEFINE ("DB_PASS", "");
DEFINE ("DB_PREFIX", "clu_");
// set up database connection
mysql_connect (DB_HOST, DB_USER, DB_PASS) or die ("could not connect");
mysql_select_db (DB_NAME) or die ( 'Unable to select database! - Please check your database settings in /php/site.config.php');
?>

then in the admin area of the script, there would be a form asking
what is company name ____________ (<- would be an input box)
..
..
..
What is zip code _______________

Then when the submit button is chosen, it would replace the inputted data from admin area into the site.config.php file. Does that make sense, I hope it does...

But the question is....How to accomplish this feat?? I have seen it before but am not that experienced of php coder to pick it out of a script thats already written. Any help would be appreciated,

Thanks in Advance

Squid
Reply With Quote
  #2 (permalink)  
Old 04-22-04, 02:16 PM
Trevor's Avatar
Trevor Trevor is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Denver, Colorado
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Sounds like a regular expression problem to me. But I do have one question. If you are already hooking up to the database, why not store these values in the database? You could preform a select statement below the db connect statements.

Most servers do allow you to write to files, but then you have to rely on an end users ability to chmod. If I were to try and accomplish this with my current knowledge, this is what I would do.

Please forgive the non-programming format. This is just random thinking.

1. Read in the file
2. Explode the file at "//database settings"
3. Use the form values to re-construct the top of the file.
3. Combine your new data with part[1] of the exploded value.
4. Write the file.

The only think I would be worried about is if something screws up and the file is corrupted. Bye-bye database connection.

Like I said, random thoughts...
__________________
The Universe Our God, Nature Our Temple, Love And Duty Our Religion, Knowledge Our Happiness And Consolation, Death The Dissolution Of The Ego, And The Return To Eternity.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP write to text file veeco Script Requests 2 02-10-10 02:48 PM
PHP form and write to file Adragon PHP 1 03-12-04 01:00 PM
php form to html file arnec PHP 1 01-21-04 10:14 AM
Write form data to file dragge PHP 1 12-27-03 07:26 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM


All times are GMT -5. The time now is 10:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.