Basically i created a some code that creates a file….
I can use that code and works perfectly in the IF statements in my code… now… because i have to use it twice… I decided to make it a function… but as soon as i make it a function it doesnt work…
anyone can tell me why??
I am just calling the function inside others IF statements as
if (createFile()) {
echo "it worked";
}
function createFile () {
//Creates File and populates it.
$fOpen = fopen($dbFile, 'w');
$fString .= "<?php\n";
$fString .= "// Database Constants\n";
$fString .= "define(\"DB_SERVER\", \"$server\");\n";
$fString .= "define(\"DB_USER\", \"$username\");\n";
$fString .= "define(\"DB_PASS\", \"$password\");\n";
$fString .= "define(\"DB_NAME\", \"$dbname\");\n";
$fString .= "?>";
fwrite($fOpen, $fString);
fclose($fOpen);
}
You need to pass in the value for $dbFile to the function. Like
This is typically considered a better approach than declaring the $dbFile variable as global inside the function.