Jump to content

[SOLVED] Variable in file_put Fuction


bob2588

Recommended Posts

i am try to make a install script for one of the script and i need it to use variables from a forum  but i am have a little trouble with it can you guy help

<?php
$test= "bob";
$file = 'db.php';
$host = '$host="$test";' ."\n";
$user = '$user="bob";' ."\n";
$pass = '$pass="test";' ."\n";
$db_name = '$$db_name="bob_ad";' ."\n";
$query ='$link = mysql_connect($host, $user, $pass);' ."\n";
$db = 'mysql_select_db($db_name);' ."\n";

file_put_contents($file, $host);
file_put_contents($file, $user, FILE_APPEND);
file_put_contents($file,$pass, FILE_APPEND);
file_put_contents($file,$db_name, FILE_APPEND);
file_put_contents($file,$query, FILE_APPEND);
file_put_contents($file,$db, FILE_APPEND);

echo"File Done <br> $test";

?>

 

 

 

 

thank bob

Link to comment
https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/
Share on other sites

not an error but the code above makes a file call db.php  and then inserts the data into it but this line is the problem  $host = '$host="$test";' ."\n";

i need $host to be wrote to the file and $test to be takeing form a forum i wrote

Should look like this when it is done

make_db.php

<?php
$test= "bob";
$file = 'db.php';
$host = '$host=" $test";' ."\n";
$user = '$user="bob";' ."\n";
$pass = '$pass="test";' ."\n";
$db_name = '$$db_name="bob_ad";' ."\n";
$query ='$link = mysql_connect($host, $user, $pass);' ."\n";
$db = 'mysql_select_db($db_name);' ."\n";

file_put_contents($file, $host);
file_put_contents($file, $user, FILE_APPEND);
file_put_contents($file,$pass, FILE_APPEND);
file_put_contents($file,$db_name, FILE_APPEND);
file_put_contents($file,$query, FILE_APPEND);
file_put_contents($file,$db, FILE_APPEND);

echo"File Done <br> $test";

?>

and what it should look like

$host="bob";
$user="bob";
$pass="test";
$db_name = "bob_ad"; 
$link = mysql_connect($host, $user, $pass);
mysql_select_db($db_name);

here is the code

<?php
$test= "bob123";
$file = 'db.php';
$host = '$host=" ' . $test . '  ";' . "\n";
$user = '$user="bob";' ."\n";
$pass = '$pass="test";' ."\n";
$db_name = '$$db_name="bob_ad";' ."\n";
$query ='$link = mysql_connect($host, $user, $pass);' ."\n";
$db = 'mysql_select_db($db_name);' ."\n";

file_put_contents($file, $host);
file_put_contents($file, $user, FILE_APPEND);
file_put_contents($file,$pass, FILE_APPEND);
file_put_contents($file,$db_name, FILE_APPEND);
file_put_contents($file,$query, FILE_APPEND);
file_put_contents($file,$db, FILE_APPEND);

echo"File Done <br> $test";

?>

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.