View Full Version : Appending PHP file with variables

05-21-2004, 01:11 PM
I'm trying to take data from a form and write them to a file 'config.inc.php' but without any luck.

The data is required to set up the configuration of a forum I'm building the installer for.

Below is my current code:

$sFilename = "../config.inc.php";
$sData = "\n\n// The following is from the install setup\n\n";
$sData .= "\$sPWBBName = ".$this->sBoardName."\n\n";
$sData .= "\$sSqlServer = ".$this->sDBHost."\n";
$sData .= "\$sSqlUser = ".$this->sDBUser."\n";
$sData .= "\$sSqlPassword = ".$this->sDBPass."\n";
$sData .= "\$sSqlDb = ".$this->sDBName."\n\n";
$sData .= "\$sTemplatePath = \"templates\"\n";
$sData .= "\$sIncPath = \"incs\"\n\n";
$sData .= "\$sPrefix = ".$this->sDBPrefix."\n";
// Lets write the data
$this->write_data($sFilename, $sData);

//Below is the function to write the data to the file...
function write_data($filename, $data)
//Appends file
$handle = fopen($filename, "a");
$finalwrite = fwrite($handle, $data);
return true;

Every time I try and run this, there doesn't appear to be any problems, apart from that it just won't write the data to the end of the file.

Does anyone have any idea as to what's going on? and do i need to add the end '?>' to the document?

Would it be easier to write a new php file to store the variables in?

Many thanks in advance

05-21-2004, 01:28 PM
try some basic error checking ..

if( !is_writable( $filename ) ){
die( $filename .' is not writable' ) ;

+ if on win32 try $handle = fopen($filename, "ab");

05-21-2004, 02:09 PM
Worked a bit on it after you posted, and the error messages pointed me in the direction that I needed to go.

Cheers :thumbsup: