Help me please. I saw this guest in the web. I like it coz its simple. I want it to connect to my login system database so that the user dont need to type his/her name into the guestbook everytime he likes to leave a message. The name that will appear in the guestbook is the one that he uses when he logged in.
I think i need another field in my database called message and date for his the messages and for the time that he posted a message.
This is my current database.
Thanks.
I think i need another field in my database called message and date for his the messages and for the time that he posted a message.
PHP Code:
<?php
$host = "localhost";
$user = "username";
$pass = "password";
$db = "database";
mysql_connect
($host, $user, $pass) OR die ("Could not connect to the server.");
mysql_select_db($db) OR die
("Could not connect to the database.");
$name = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);
if (!isset($_POST['txtName'])) {
$query = "SELECT id, name, message, DATE_FORMAT
(date, '%D %M, %Y @ %H:
%i') as newdate FROM guests ORDER BY id DESC";
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)) {
?>
<p><strong><?php echo $row->message; ?></strong>
<br />Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?></p>
<?php
}
?>
<p>Post a message</p>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p><label for="txtName">Name:</label><br />
<input type="text" title="Enter your name" name="txtName" /></p>
<p><label for="txtMessage">Your message:</label><br />
<textarea title="Enter your message" name="txtMessage"></textarea></p>
<p><label title="Send your message">
<input type="submit" value="Send" /></label></p>
</form>
<?php
}
else {
// Adds the new entry to the database
$query = "INSERT INTO guests SET message='$message', name='$name', date=NOW
()";
$result = mysql_query($query);
// Takes us back to the entries
$ref = $_SERVER['HTTP_REFERER'];
header ("Location: $ref");
}
?>
PHP Code:
username varchar(30) primary key,
password varchar(32),
userid varchar(32),
userlevel tinyint(1) unsigned not null,
email varchar(50),
timestamp int(11) unsigned not null
Comment