0

I am a fairly new with PHP and I am in need of help in creating repeated string post

The code I have is listed below, what it currently does is when a user types into the comment field and then clicks the post button it post the string that was in the comment field to the bottom of the page

So for example when I type in another comment after the previous comment I still want the comment that was previously there but with the new comment above it sort of like facebook

<?php
$comment = "";

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$comment = input($_POST["comment"]);
}

function input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>Comment Post </h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
<br><br>
Comment: <textarea name="comment" rows="7" cols="40"></textarea>
<br><br>
<input type="submit" name="submit" value="Post"> 
</form>

<?php
echo "<h2>Input:</h2>";
echo $comment;
?>

<?php
echo "<h1>Input:</h1>";
echo $comment;

?>

</body>
</html>
3
  • 6
    Store it in database and then retrieve using mysql query and use ORDER BY DESC to get the latest comment.. Commented Dec 11, 2013 at 4:26
  • @Joke_Sense10 I understand that I would have to use ORDER BY DESC within the the mysql database I have but how would I use a mysql query on this? Commented Dec 11, 2013 at 5:05
  • stackoverflow.com/questions/5014946/… Commented Dec 11, 2013 at 5:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.