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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.