Adding date & <BR> to an apended comments page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AbrasiveRock
Forum Commoner
Posts: 40
Joined: Sat Feb 08, 2003 10:47 pm
Location: Olympia,WA
Contact:

Adding date & <BR> to an apended comments page

Post by AbrasiveRock »

Ok, the ultra newbie is back with another question. As part of my learning of PHP, the school I work at has let me use the making of their website as a testing bed of sorts. What I am trying to do is create a way they can easily post thier weekly classroom newsletters. I want the date right above each post as well as a <P> at the end to seperate each post. here is what I have so far...am I even close?

Code: Select all

<?php
if ($_POST&#1111;'submit']=="submit") &#123;
	$savestring = $_POST&#1111;'date'] "<br>" &#1111;'newsletter'].  "<P>\n";
	$fp = fopen("newsletter.txt","a");
	fwrite($fp,$savestring);
	fclose($fp);

header("Location: http://www.carrasdesign.com/test/newsletterdisplay.php");
&#125;
?>
<html><body>
<form action="<?php echo $_SERVER&#1111;'PHP_SELF'] ?>" method=post >
<pre>
Type or paste your info below:<br><textarea rows=23 cols=92 name='newsletter'></textarea>
<input type=submit value=submit name="submit">
</form>

</body>
</html>
I have tested all the parts and the only thing that seems to be wrong is the way that I do the line...

Code: Select all

$savestring = $_POST&#1111;'date'] "<br>" &#1111;'newsletter'].  "<P>\n";


Can anyone help me figure out what I did wrong here. Thanks.
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Post by mikusan »

I don't quite understand the way you coded the first part but the one you asked in particular should look like:

Code: Select all

$savestring = $_POST['date'] . '<br>' .  $newsletter  '<P>';
single or double quotes don't matter... but i wasn't sure what ['newsletter'] was supposed to be... so i figured it was some sorta variable... i suggest you review a tutorial on strings in particular string concatenation....
AbrasiveRock
Forum Commoner
Posts: 40
Joined: Sat Feb 08, 2003 10:47 pm
Location: Olympia,WA
Contact:

Post by AbrasiveRock »

Hmmm? That just gave me "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /web/carrasdesign/test/newsletteredit.php on line 3"

Maybe it would help if I gave you the original 'working' version that I went from?

Code: Select all

<?php
if ($_POST&#1111;'submit']=="submit") &#123;
	$savestring = $_POST&#1111;'comment'] .  "\n";
	$fp = fopen(".written","w");
	fwrite($fp,$savestring);
	fclose($fp);

header("Location: http://www.abrasiverock.com/write2file/display.php");
&#125;
?>
<html><body>
<form action="<?php echo $_SERVER&#1111;'PHP_SELF'] ?>" method=post >
<pre>
Type or paste your info below:<br><textarea rows=23 cols=92 name='comment'></textarea>
<input type=submit value=submit name="submit">
</form>

</body>
</html>
I changed the access mode 'w' to an 'a' so that it adds comments instead of replace comments. Then on the line that I changed the word 'comments' to newsletter and added the date function and the <BR> & <P> to seperate each comment...or at least that's what I was trying to do. :oops:

Does all that make more sense?

I am a major newbie and I do have a lot to learn about a great many things in PHP. Right after I made this post I was re-reading the page in my PHP book about concatenation and it did give me a few ideas, but right now I'm too tired to remember any of it. :D
AbrasiveRock
Forum Commoner
Posts: 40
Joined: Sat Feb 08, 2003 10:47 pm
Location: Olympia,WA
Contact:

Post by AbrasiveRock »

Just wanted everyone to know that with the help of a friend in the 'real' world, I got it all figured out and it works great. In case you all wondered what it was that I was tying to do...

Code: Select all

<?php 
if ($_POST&#1111;'submit']=="submit") &#123; 
   $savestring = date("m/d/y") . "<br>" . $_POST&#1111;'newsletter'] .  "<P>"; 
   $fp = fopen("test.txt","a"); 
   fwrite($fp,$savestring); 
   fclose($fp); 

header("Location: http://www.abrasiverock.com/write2file/display.php"); 
&#125; 
?> 
<html><body> 
<form action="<?php echo $_SERVER&#1111;'PHP_SELF'] ?>" method=post > 
<pre> 
Type or paste your info below:<br><textarea rows=23 cols=92 name='newsletter'></textarea> 
<input type=submit value=submit name="submit"> 
</form> 

</body> 
</html>
I'm also posting this because it's a really cool and useful script that many of the newbies might want to use. Again, thanks for everyone's patience.
Post Reply