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
https://forums.phpfreaks.com/topic/203454-fwrite-question/
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
https://forums.phpfreaks.com/topic/203454-fwrite-question/#findComment-1065854
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.