General Community > Scripting Help

What am i doing wrong?

(1/1)

Acf:
I am making a installer and i would like to put the db, user and pw in a file with a form.

This is what i made so far (it does display some parse errors).


--- Code: ---<?php
$file = fopen ("Dbconfig.php","a" ); 
if(!$file)
  {
    echo "Failed to open Dbconfig.php\n";

  } else {
    fputs($file, "<");
   fputs($file, "?php \n");
   fputs($file, "$user ="$t1"; \n");
   fputs($file, "$wachtwoord ="$t2"; \n");
   fputs($file, "$database ="$t3"; \n");
   fputs($file, "$server ="$t4"; \n");
    fputs($file, "?");
   fputs($file, "> \n");
    fclose($file);
    echo "Dbconfig.php written correctly\n";
  }
?>
--- End code ---
 

This what the file should look like after the form is used.


--- Code: ---<?php
$user ="username";
$wachtwoord ="Password";
$database ="databasename"; 
$server ="localhost";
?>
--- End code ---

 

*acf

Spaceman-Spiff:
using the highlighter u can find the mistake easier:
<?php
   fputs($file, "$user ="$t1"; \n");
   fputs($file, "$wachtwoord ="$t2"; \n");
   fputs($file, "$database ="$t3"; \n");
   fputs($file, "$server ="$t4"; \n");
?>

you didn't escape the " inside "

Acf:
Parse error: parse error in /home/thecrew/public_html/aliencowfarm/test/Install.php on line 5

thanx if don so but now i get the error above.


<?php
$file = fopen ("Dbconfig.php","a" ); 
if(!$file)
  {
    echo "Failed to open Dbconfig.php\n";

  } else {
   fputs($file, "<");
   fputs($file, "?php \n");
   fputs($file, "$user =\"$t1\"; \n");
   fputs($file, "$wachtwoord =\"$t2\"; \n");
   fputs($file, "$database =\"$t3\"; \n");
   fputs($file, "$server =\"$t4\"; \n");
   fputs($file, "?");
   fputs($file, "> \n");
   fclose($file);
    echo "Dbconfig.php written correctly\n";
  }
?>

[Unknown]:
For $user =, etc. you need to escape the $ since you are using double quotes.

-[Unknown]

Acf:
Thanx Spaceman-Spiff and  [Unknown] ,  it works like a dream!  :)  :)  :)

Navigation

[0] Message Index

Go to full version