ashish2 Posted April 7, 2009 Share Posted April 7, 2009 Hi frends, i m new to php...so please forgive me if i asked any foolish question. i wanted to know...abt comment script. here this is my file. 1.php: <html><head> <title>Practice</title> </head><body><h1> Welcome </h1> <hr> <?php // giving variable names to form data $name = $_POST['name']; $email = $_POST['email']; $blog = $_POST['blog']; $comments = $_POST['comments']; //displaying & printing form data on page echo "Posted by: "; echo "<a href=" . $blog . ">" . $name . "</a>"; echo "<BR>"; echo $comments; ?> <?php //writing form data to text file, 'data1.txt' $handle= fopen("data1.txt","a"); fwrite($handle,'name' . "\n"); fwrite($handle, '~'); fwrite($handle,'email' . "\n"); fwrite($handle, '~'); fwrite($handle,'blog' . "\n"); fwrite($handle, '~'); fwrite($handle,"comments" . "\n\n"); fwrite($handle, '|~|'); fclose($handle); ?> <hr> <!-- html form below --> <form action="1.php" method="post"> Name:<br> <input type="text" name="name" /><br> Email:<br> <input type="text" name="email" id="email"/><br> Website/Blog url:<br><input type='text' name='blog' id='blog' value='http://' /><br> Comments:<br><textarea rows=5 cols=27 name='comments' id='comments'> </textarea><br> <input type="submit" value='Submit'/> </form> <!-- end of form --> </body> </html> the problem i face is, when i type 1st comment, it shows on the page. & then, when i type, 2nd comment, the 2nd comment replaces the 1st comment, the 1st comment disappears from the screen. the 3rd comment makes the 2nd comment disappear. so on. how can i get all the comments on the page? Link to comment https://forums.phpfreaks.com/topic/152967-how-to-solve-this/ Share on other sites More sharing options...
JasonLewis Posted April 7, 2009 Share Posted April 7, 2009 What you need to do is look into loops. Google PHP Loops and you should be given things like for(), foreach() and while(). You basically need to "loop" through all the data that is in the file and display it, instead of selecting only one. Link to comment https://forums.phpfreaks.com/topic/152967-how-to-solve-this/#findComment-803366 Share on other sites More sharing options...
ashish2 Posted April 7, 2009 Author Share Posted April 7, 2009 ok ... so supposing if i use a for() loop ... wat are the conditions that go into the loop ?? is it the page url ? i mean, when the 2nd comment needs to be posted.. does the page url of the 2nd comment differs from the 1st page? if thats the case then, how do i change the page url? Thanks in Advance. Link to comment https://forums.phpfreaks.com/topic/152967-how-to-solve-this/#findComment-803398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.