bob2588 Posted October 27, 2009 Share Posted October 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/ Share on other sites More sharing options...
cags Posted October 27, 2009 Share Posted October 27, 2009 You say your having trouble and give a brief description of what your trying to do, but you didn't actually state what trouble you were having, are you getting an error? Does it just not do what you expect? Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945282 Share on other sites More sharing options...
bob2588 Posted October 27, 2009 Author Share Posted October 27, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945285 Share on other sites More sharing options...
cags Posted October 27, 2009 Share Posted October 27, 2009 $host = '$host="' . $test . '";' . "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945292 Share on other sites More sharing options...
Alex Posted October 27, 2009 Share Posted October 27, 2009 The strings are causing you problems. Double quotes parse variables while single quotes do not, so you need to do something like this: eg $host = '$host="' . $test . '";' . "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945294 Share on other sites More sharing options...
bob2588 Posted October 27, 2009 Author Share Posted October 27, 2009 i try that now i get this error Parse error: syntax error, unexpected '"' in /home/bob/public_html/ad/Install/test2.php on line 4 Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945300 Share on other sites More sharing options...
trq Posted October 27, 2009 Share Posted October 27, 2009 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945304 Share on other sites More sharing options...
bob2588 Posted October 27, 2009 Author Share Posted October 27, 2009 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945307 Share on other sites More sharing options...
trq Posted October 27, 2009 Share Posted October 27, 2009 No syntax errors there. You might want to fix this extra $ though.... $db_name = '$$db_name="bob_ad";' ."\n"; Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945315 Share on other sites More sharing options...
bob2588 Posted October 27, 2009 Author Share Posted October 27, 2009 there not an error with the code dreamweaver was missing up i hate it upload thing :/ thanks for all the help Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945316 Share on other sites More sharing options...
bob2588 Posted October 27, 2009 Author Share Posted October 27, 2009 No syntax errors there. You might want to fix this extra $ though.... $db_name = '$$db_name="bob_ad";' ."\n"; thnaks yes it was dream weaver Quote Link to comment https://forums.phpfreaks.com/topic/179172-solved-variable-in-file_put-fuction/#findComment-945317 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.