Jump to content

[SOLVED] Output $ symbol in PHP script


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

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.