Im making an install script for a AOL Instant messanger Guestbook that i made.. I got it to write in the config.php because all that needs to be there is this:
<?
$dbhost = "localhost" ;
$databees = "database" ;
$dbusername = "username" ;
$dbpassword = "pass"
?>
Ok, now on the actual page needed to view it i have to have more code than that. but when i use the same code, the only code i know to do this, it erases everything and just pastes that info into it.
I dont want it to erase everything just add that info to it.
To get it to write in the config.php i am using this script.
$fp = fopen ("config.php", "w+");
fwrite($fp, "<?\n ");
fwrite($fp, $hoststring);
fwrite($fp, $databasestring);
fwrite($fp, $dbusernamestring);
fwrite($fp, $dbpasswordstring);
fwrite($fp, "?>");
fclose($fp);
Im stupid when it comes to php so please help. Thanks.
ADDING TO FILES *THIS NOOB NEEDS HELP*
Moderator: General Moderators
Use "r+" (open a file for reading & writing).
The following places the new data at the beginning of the file:
The following places the new data at the beginning of the file:
Code: Select all
$fp = fopen ("config.php", "r+");
$data = fread($fp, filesize("config.php"));
fseek($fp, 0);
ftruncate($fp, 0); // Unsafe (but very rarely)
fwrite($fp, "<?\n ");
fwrite($fp, $hoststring);
fwrite($fp, $databasestring);
fwrite($fp, $dbusernamestring);
fwrite($fp, $dbpasswordstring);
fwrite($fp, "?>");
fwrite($fp, $data); // Write the old data
fclose($fp);- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact: