Jump to content

[SOLVED] Output $ symbol in PHP script


Guest

Recommended Posts

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&#36;dbhost = \"$dbhost\";\n&#36;dbuser = \"$dbuser\";\n&#36;dbpass = \"$dbpass\";\n&#36;dbname = \"$dbname\";\n&#36;connection = mysql_connect(&#36;dbhost, &#36;dbuser, &#36;dbpass) or die(\"Unable to connect to &#36;dbname! \".mysql_error().\".\");\nmysql_select_db(&#36;dbname) or die(\"Unable to select &#36;dbname! \".mysql_error().\".\");\n?>");
  fclose($handle);

 

The problem is that the file it generates looks like this:

 

<?php
&#36;dbhost = "localhost";
&#36;dbuser = "root";
&#36;dbpass = "zissou1";
&#36;dbname = "cmsnap";
&#36;connection = mysql_connect(&#36;dbhost, &#36;dbuser, &#36;dbpass) or die("Unable to connect to &#36;dbname! ".mysql_error().".");
mysql_select_db(&#36;dbname) or die("Unable to select &#36;dbname! ".mysql_error().".");
?>

 

It isn't converting the &#36; to a $ symbol. When I replace &#36; 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?

Link to comment
https://forums.phpfreaks.com/topic/117414-solved-output-symbol-in-php-script/
Share on other sites

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.