Jump to content

[SOLVED] php write


bob2588

Recommended Posts

i am try to make a php file called db_2.php i can make the files but i am have a hard time getting the varables in to the file the files should loook like this

 

<?php
$host = "localhost";
$user = "user"; 
$pass = "pass"; 
$db_name = "bob_ad"; 
//database connection
$link = mysql_connect($host, $user, $pass);
mysql_select_db($db_name);

but the code put this in there

='localhost';
='user';

and last is the php file that does the writing

<?php
$makedb = "db_2.php";
$fh = fopen($makedb, 'w') or die("can't open file");
$stringData = "$host='localhost';\n";
fwrite($fh, $stringData);
$stringData = "$user='user';\n";
fwrite($fh, $stringData);
fclose($fh);

?>

does any have any idea's

thanks bob

Link to comment
https://forums.phpfreaks.com/topic/178869-solved-php-write/
Share on other sites

Your problem is that it's trying to actually parse $host as a variable, which has no value. So instead you should be using single quotes which don't parse variables.

 

eg

$stringData = '$host="localhost";' . "\n";

You could also make things easier on yourself and use file_put_contents() which acts the same way as fopen(), fwrite() and fclose(), just making it simpler for you.

Link to comment
https://forums.phpfreaks.com/topic/178869-solved-php-write/#findComment-943648
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.