Jump to content

fwrite question


bschultz

Recommended Posts

I'm trying to write some variable values to a separate file.  That separate file will be used in an include on a third file.

 

File1 is a simple html form

 

File2 processes that form, and writes the data to File3

 

File4 reads the variables from File3 and compares them to a database...and prints out the results.

 

File1, File3 and File4 all work fine.  File2 (which uses fwrite) isn't writing the variable name to the file.

 

Here's the code:

 

<?php
$myFile = "testFile.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "

<?php
\n\n

$your_page_title = \"$_POST[your_page_title]\";\n
$your_number_color = \"$_POST[your_number_color]\";\n
$your_position_color = \"$_POST[your_position_color]\";\n
$your_name_size = \"$_POST[your_name_size]px\";\n
$your_stats_color = \"$_POST[your_stats_color]\";\n
?>
";

fwrite($fh, $stringData);
fclose($fh);
?>

 

The above code writes this to the file

 

= "My Title";

= "green";

= "blue";

= "14px";

= "red";

 

As you can see, none of the variable names are written to the file.

 

It should read this

 

$your_page_title = "My Title";

$your_number_color = "green";

$your_position_color = "blue";

$your_name_size = "14px";

$your_stats_color = "red";

 

How can I get the variable names to be written to the file?

 

Thanks.

Link to comment
Share on other sites

try this

<?php
$myFile = "testFile.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "<?php
\n\n

\$your_page_title = \"$_POST[your_page_title]\";\n
\$your_number_color = \"$_POST[your_number_color]\";\n
\$your_position_color = \"$_POST[your_position_color]\";\n
\$your_name_size = \"$_POST[your_name_size]px\";\n
\$your_stats_color = \"$_POST[your_stats_color]\";\n
?>
";

fwrite($fh, $stringData);
fclose($fh);
?>

Link to comment
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.