Jump to content

fwrite() is dropping my variables!


macattack

Recommended Posts

I have this code:

$postContent = "<?php $content=".$_POST['content']."; $date=".$_POST['date']."; echo '<h2>$content</h2><br><br>Posted on $date by ".BLOG_AUTHOR."; ?>";

 

and this is what fwrite() is putting in the file:

<?php =Write your text here.; =2008/05/26; echo '<h2></h2><br><br>Posted on  by BLOG_AUTHOR; ?>

 

essentially, it's stripping everything with a dollar sign in front of it. Any tips on how to rectify the situation?

 

Note: I don't want it to save the $_POST parts, just their value, in case that wasn't clear.

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/107325-fwrite-is-dropping-my-variables/
Share on other sites

Thanks BlueSkyIs. The problem isn't over, but it's a step forward now. Pocobueno1388: I do want to write the "<?php" and "?>" tags, the point of the file is to be a short PHP script to display the variables that were entered in a form on a blog, so that I can retrieve the values later.

 

This is the current code:

$postContent = '<?php $content = "'.stripslashes($_POST['content']).'"; $date = "'.$_POST['date'].'"; echo "<h3>$content</h3><br><br>Posted on $date by '.BLOG_AUTHOR.'; ?>';

 

I realised the error was the I wasn't saving as a PHP file. However, it's now showing an error that there is a $end in line 1, I'm guessing that that is because there are no line breaks? How do I get past that error?

 

Thanks again for your help!

That appeared to be the problem. Thanks. However, it still wouldn't display on my page, so I made a few more code changes, and it still won't display.

 

I now have it like this:

$postContent = '<?php $theGoods = "'.stripslashes($_POST['content']).'"; $postedDate = "'.$_POST['date'].'"; ?>';

 

Then, the function printBlog() calls up the blog post, and I ask the function to echo the data.

function printBlog($blog){
list($date) = sscanf($_GET['title'], "%s %d");
echo "<h3>".pathinfo($blog, PATHINFO_FILENAME)."</h3>";
$dir = $entry;
$fp = fopen($blog, 'rb');
if(!($fp = fopen($blog, 'rb'))) echo "File failed to open";  
$data = fread($fp, filesize($blog));
fclose($fp);
echo $data;
echo "<h2>".$theGoods."</h2><br><br><h4>Published on ".$postedDate." by ".BLOG_AUTHOR."</h4>";
}

 

The blog won't display, but when I call up the page source, $theGoods and $postedDate show up as the information that they should be. Is there a suggestion as to why? Thanks again for your help!

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.