<?php
$host = 'localhost';
$user = 'root';
$passwd = '';
$base = 'book';
$db = new MySQLi($host, $user, $passwd, $base);
if (isset($_POST['submit'])) {
$db->query("INSERT INTO messages SET
time = '".time()."',
user = '".$_POST['user']."',
message = '".$_POST['message']."'
");
}
$content = '';
$query = $db->query("SELECT * FROM messages ORDER BY time DESC");
if ($query->num_rows > 0) {
while($data = $query->fetch_assoc()) {
$content .= '#'.$data['id'].' <b>'.$data['user'].'</b> ('.date('d.m.Y / H:i').'): '.$data['message'].'<br />';
}
} else {
$content = 'Сообщений нет!';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Гостевая на PHP + MySQLi</title>
</head>
<body>
<form method="post" action="">
Имя:<br />
<input name="user" maxlength="50" value="" /><br />
Сообщение:<br />
<textarea cols="25" rows="5" name="message"></textarea><br />
<input value="Добавить" type="submit" name="submit" />
</form>
<hr />
<?php echo $content; ?>
</body>
</html>