macattack Posted May 26, 2008 Share Posted May 26, 2008 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 More sharing options...
BlueSkyIS Posted May 26, 2008 Share Posted May 26, 2008 try escaping dollar signs with \ $postContent = "<?php \$content=".$_POST['content']."; \$date=".$_POST['date']."; echo <h2>\$content</h2><br><br>Posted on \$date by ".BLOG_AUTHOR."; ?>"; Link to comment https://forums.phpfreaks.com/topic/107325-fwrite-is-dropping-my-variables/#findComment-550274 Share on other sites More sharing options...
pocobueno1388 Posted May 26, 2008 Share Posted May 26, 2008 Do you want it to write the PHP tags (<?php)? I think what your meaning to do is this <?php $content= $_POST['content']; $date= $_POST['date']; $postContent = "<h2>$content</h2><br><br>Posted on $date by ".BLOG_AUTHOR; ?> Link to comment https://forums.phpfreaks.com/topic/107325-fwrite-is-dropping-my-variables/#findComment-550276 Share on other sites More sharing options...
macattack Posted May 26, 2008 Author Share Posted May 26, 2008 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! Link to comment https://forums.phpfreaks.com/topic/107325-fwrite-is-dropping-my-variables/#findComment-550291 Share on other sites More sharing options...
BlueSkyIS Posted May 26, 2008 Share Posted May 26, 2008 looks like you need to close the double-quote on the very end: $postContent = '<?php $content = "'.stripslashes($_POST['content']).'"; $date = "'.$_POST['date'].'"; echo "<h3>$content</h3><br><br>Posted on $date by '.BLOG_AUTHOR.'"; ?>'; Link to comment https://forums.phpfreaks.com/topic/107325-fwrite-is-dropping-my-variables/#findComment-550293 Share on other sites More sharing options...
macattack Posted May 26, 2008 Author Share Posted May 26, 2008 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! Link to comment https://forums.phpfreaks.com/topic/107325-fwrite-is-dropping-my-variables/#findComment-550301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.