...

View Full Version : Write and Replace?



dniwebdesign
10-23-2004, 09:51 AM
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
$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
$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.

Nightfire
10-23-2004, 12:41 PM
Get all your form info, write it into a variable, save to file



// 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);
?>

dniwebdesign
10-23-2004, 07:34 PM
alrighty, i'll give that a shot... thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum