Jump to content

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";

?>

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.