Page 1 of 1
Adding date & <BR> to an apended comments page
Posted: Tue May 20, 2003 2:39 pm
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ї'submit']=="submit") {
$savestring = $_POSTї'date'] "<br>" ї'newsletter']. "<P>\n";
$fp = fopen("newsletter.txt","a");
fwrite($fp,$savestring);
fclose($fp);
header("Location: http://www.carrasdesign.com/test/newsletterdisplay.php");
}
?>
<html><body>
<form action="<?php echo $_SERVERї'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ї'date'] "<br>" ї'newsletter']. "<P>\n";
Can anyone help me figure out what I did wrong here. Thanks.
Posted: Tue May 20, 2003 7:10 pm
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....
Posted: Wed May 21, 2003 4:15 am
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ї'submit']=="submit") {
$savestring = $_POSTї'comment'] . "\n";
$fp = fopen(".written","w");
fwrite($fp,$savestring);
fclose($fp);
header("Location: http://www.abrasiverock.com/write2file/display.php");
}
?>
<html><body>
<form action="<?php echo $_SERVERї'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.
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.

Posted: Tue May 27, 2003 1:23 am
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ї'submit']=="submit") {
$savestring = date("m/d/y") . "<br>" . $_POSTї'newsletter'] . "<P>";
$fp = fopen("test.txt","a");
fwrite($fp,$savestring);
fclose($fp);
header("Location: http://www.abrasiverock.com/write2file/display.php");
}
?>
<html><body>
<form action="<?php echo $_SERVERї'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.