Problems populating a file with PHP
<p>Basically my problem is the next one... the following script connects a the DB and creates a file.... everything works fine.. except that when it populates the file.. it doesn't put the variables <code>$username</code>, <code>$password</code>, <code>$server</code> and <code>$dbname</code> into the file.
the created file looks like this </p>

<pre><code>&lt;?php

    // Database Constants
    $DB_SERVER ="";
    $DB_USER ="";
    $DB_PASS ="";
    $DB_NAME ="";
    ?&gt;
</code></pre>

<p>but it should have something inside the quotes :S</p>

<p>my script is as follows</p>

<pre><code>&lt;?php 
//DB Config File
$dbFile = 'dbconfig.php';

function createfile ($dbFile) {
        //Creates File and populates it.
        $fOpen = fopen($dbFile, 'w');

            $fString .= "&lt;?php\n";
            $fString .= "// Database Constants\n";
            $fString .= "\$DB_SERVER =" . "\"" . $server . "\";\n";
            $fString .= "\$DB_USER =" . "\"" . $username . "\";\n";
            $fString .= "\$DB_PASS =" . "\"" . $password . "\";\n";
            $fString .= "\$DB_NAME =". "\"" . $dbname . "\";\n";
            $fString .= "?&gt;";

        fwrite($fOpen, $fString);
        fclose($fOpen);
return true;
}


if (isset($_POST['submit'])) {

$username = $_POST['username'];
$password = $_POST['password'];
$server = $_POST['server'];
$dbname = $_POST['dbname'];


try {
$db = new PDO ('mysql:host=' .$server.';dbname='.$dbname,$username,$password);

if ($db) { //if succesful at connecting to the DB

if (file_exists($dbFile)){
    if (is_readable($dbFile) &amp;&amp; is_writable($dbFile)){ 

        //Creates File, populates it and redirects the user

    if (createfile($dbFile)) { 
    header("Location: http://http://localhost/proj11/install2.php");
    exit ();
            }


        } else { 

        $msg = "2The file {$dbFile} cannot be accessed. Please configure the file manualy or grant Write and Read permission.";  }

    } else {

        //Creates File, populates it and redirects the user

    if (createfile($dbFile)) {

    header("Location: http://http://localhost/proj11/install2.php");
    exit ();
            }

        }


}

} catch (PDOException $e) { //Catchs error if can't connect to the db.
    $msg = 'Connection failed: ' . $e-&gt;getMessage();
}


}


?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form id="iForm" method="post" action="install.php"&gt;
&lt;label id="username" &gt;Username&lt;/label&gt;
&lt;input id="username" name="username"/&gt;
&lt;label id="password"&gt;Password&lt;/label&gt;
&lt;input id="password" name="password" /&gt;
&lt;label id="server" &gt;Server&lt;/label&gt;
&lt;input id="server" name="server"/&gt;
&lt;label id="dbName" &gt;dbName&lt;/label&gt;
&lt;input id="dbName" name="dbname"/&gt;

&lt;input type="submit" name="submit" value="submit" /&gt;
&lt;/form&gt;
&lt;p id="error"&gt;&lt;?php echo $msg ?&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
