Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-23-2004, 09:51 AM   PM User | #1
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
Write and Replace?

I've never did this before so I would really like some help. I have a file named
db.inc.php which holds the following code:
PHP Code:
<?php
$dbusername 
'';
$dbpasswd '';
$dbhost '';
$database_name '';
$database_prefix '';
?>
I would like to know what code I would need to take info from a form and re-write the file so the code in it looks like:
PHP Code:
<?php
$dbusername 
'xxxxx';
$dbpasswd 'xxxxx';
$dbhost 'localhost';
$database_name 'xxxxx';
$database_prefix 'xxxxx';
?>
In other words it would be kind of like a install script. Thanks.
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com
dniwebdesign is offline   Reply With Quote
Old 10-23-2004, 12:41 PM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
Get all your form info, write it into a variable, save to file

PHP Code:
// form submitted
$config = '<?php 
$dbusername 
'' $_POST['dbusername'] .'\'; 
$dbpasswd = \'' 
$_POST['dbpasswd'] .'\'; 
$dbhost = \'' 
$_POST['dbhost'] .'\'; 
$database_name = \'' 
$_POST['database_name'] .'\'; 
$database_prefix = \'' 
$_POST['database_prefix'] .'\'; 
?>'
;

// do all your file writing here
$handle fopen("db.inc.php","w+");
fputs($handle,$config);
fclose($handle);
?>
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 10-23-2004, 07:34 PM   PM User | #3
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
alrighty, i'll give that a shot... thanks.
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com
dniwebdesign is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:17 AM.


Advertisement
Log in to turn off these ads.