Hey,
This is me practicing so it's not although great. Saying that, even if it was my best attempt it probably wouldn't be all that great.
Index.php
<?php
include ('connect.inc.php');
$display = $_POST['display'];
if (isset($_POST['name'], $_POST['comment'])) {
add_comment($_POST['name'], $_POST['comment']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://wwww.w3.org/TR/xhtml1/DTD/dhtml1-strict.dtd">
<html xlmns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> </title>
</head>
<body>
<form action="" method="POST">
Name: <p><input type="text" name="name" /></p>
Comment: <p><textarea name="comment" rows="10" cols="100"></textarea></p>
Number of posts <p><input type="text" name="display" /> </p>
<p><input type="submit" value="Submit Comment" /></p>
</form>
<p>
<?php
$query = "SELECT `post_id`, `user_name`, `user_comment`, `date` FROM `wall` ORDER BY `date` DESC LIMIT 0, {$display}";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
// Gather all $row values into local variables for easier usage in output
echo '<strong>Date: </strong>',$row["date"].'<br />';
echo '<strong>Name: </strong>',$row["user_name"].'<br />';
echo '<strong>Comment: </strong>',$row["user_comment"].'<br />';
echo '<hr />';
}
?>
</p>
</body>
</html>
connect.inc.php
<?php
mysql_connect('localhost','root','');
mysql_select_db('wall');
function add_comment($name, $text) {
$name = mysql_real_escape_string($name);
$text = mysql_real_escape_string($text);
$date = date("D j M Y (G:i:s)");
mysql_query("INSERT INTO `wall` (`user_name`, `user_comment`, `date`) VALUES ('{$name}', '{$text}', '{$date}')");
}
?>
There you go.