Guest Posted July 30, 2008 Share Posted July 30, 2008 I'm writing a script that should create a file named dbconnect.php. This is what I have so far: $dbhost = $_POST['dbhost']; $dbuser = $_POST['dbuser']; $dbpass = $_POST['dbpass']; $dbname = $_POST['dbname']; $handle = fopen("dbconnect.php", "wt"); fwrite($handle, "<?php\n$dbhost = \"$dbhost\";\n$dbuser = \"$dbuser\";\n$dbpass = \"$dbpass\";\n$dbname = \"$dbname\";\n$connection = mysql_connect($dbhost, $dbuser, $dbpass) or die(\"Unable to connect to $dbname! \".mysql_error().\".\");\nmysql_select_db($dbname) or die(\"Unable to select $dbname! \".mysql_error().\".\");\n?>"); fclose($handle); The problem is that the file it generates looks like this: <?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = "zissou1"; $dbname = "cmsnap"; $connection = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to $dbname! ".mysql_error()."."); mysql_select_db($dbname) or die("Unable to select $dbname! ".mysql_error()."."); ?> It isn't converting the $ to a $ symbol. When I replace $ with $ in the fwrite function, it just echoes those function values and then it looks like this: <?php localhost = "localhost"; root = "root"; zissou1 = "zissou1"; cmsnap = "cmsnap"; = mysql_connect(localhost, root, zissou1) or die("Unable to connect to cmsnap! ".mysql_error()."."); mysql_select_db(cmsnap) or die("Unable to select cmsnap! ".mysql_error()."."); ?> How do I fix this? Quote Link to comment https://forums.phpfreaks.com/topic/117414-solved-output-symbol-in-php-script/ Share on other sites More sharing options...
Guest Posted July 30, 2008 Share Posted July 30, 2008 Er ignore all the #38; symbols. Those were generated when I tried to post D: Quote Link to comment https://forums.phpfreaks.com/topic/117414-solved-output-symbol-in-php-script/#findComment-603935 Share on other sites More sharing options...
Sulman Posted July 30, 2008 Share Posted July 30, 2008 Have you tried escaping the dollar sign?: <?php fwrite($handle, "<?phpn\n \$dbhost = \"$dbhost\"...etc ?> Quote Link to comment https://forums.phpfreaks.com/topic/117414-solved-output-symbol-in-php-script/#findComment-603938 Share on other sites More sharing options...
DarkWater Posted July 30, 2008 Share Posted July 30, 2008 You need to escape it or write it in single quotes. Either: $string = "\$something = 'Lol';"; Or: $string = '$something = "Lol";'; Quote Link to comment https://forums.phpfreaks.com/topic/117414-solved-output-symbol-in-php-script/#findComment-603939 Share on other sites More sharing options...
KevinM1 Posted July 30, 2008 Share Posted July 30, 2008 Just escape it: $dollars = 20; echo "I have \$$dollars."; Quote Link to comment https://forums.phpfreaks.com/topic/117414-solved-output-symbol-in-php-script/#findComment-603940 Share on other sites More sharing options...
Guest Posted July 30, 2008 Share Posted July 30, 2008 That's really obvious, why didn't I think of that Quote Link to comment https://forums.phpfreaks.com/topic/117414-solved-output-symbol-in-php-script/#findComment-603970 Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 It's always the easy ones that are hard to find lol Quote Link to comment https://forums.phpfreaks.com/topic/117414-solved-output-symbol-in-php-script/#findComment-603973 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.