I made a premature guestbook for my site using PHP and MySQL. For some reason when I use the SELECT statement ... my first guestbook entry doesn't show, but all subsequent entries show.
My site is:
http://tearsfall.pcriot.com
My guestbook is:
http://tearsfall.pcriot.com/guestbook.php
I'm using the mysql_escape_string() for the guestbook, for some reason it works without the escape string.
Here is my guestbook.php code:
here is my guestbook_process.php code:
My guestbook database is defined as follows
guestbook(messageID,guest_name,message_post)
My site is:
http://tearsfall.pcriot.com
My guestbook is:
http://tearsfall.pcriot.com/guestbook.php
I'm using the mysql_escape_string() for the guestbook, for some reason it works without the escape string.
Here is my guestbook.php code:
Code:
<html>
<head>
<title>Guestbook v1.061</title>
</head>
<body text="#000000">
<p align="center">
<table border="1" cellpadding="0" cellspacing="0" width="33%">
<?php
require "connect.php";
$query = "SELECT * FROM guestbook";
$result = mysql_query($query) or die(mysql_error());
if(mysql_fetch_array($result)=="") {
echo "<tr rowspan='2'><td width='100%'>";
echo "No entries.";
echo "</td></tr>";
}
else {
while($row = mysql_fetch_array($result)) {
echo "<tr><td width='100%' bgcolor='#666666'>";
echo "<font color='#FFFFFF'><strong> ";
echo $row['messageID'] . " " . $row['guest_name'];
echo "</strong></font>";
echo "</td></tr>";
echo "<tr><td width='100%' bgcolor='#999999'>";
echo $row['message_post'];
echo "</td></tr>";
}
}
mysql_close($connection);
?>
</table>
</p>
<p align="center">
Add to the guestbook. The current supported form is for guests. Registered users will eventually be supported.
</p>
<form id="guestbook" method="post" action="./guestbook_process.php">
<p align="center">
<table border="1" cellspacing="0" cellpadding="0" width="33%">
<tr>
<td align="center">Guest name: <input type="text" id="guest_name" name="guest_name" /></td>
</tr>
<tr>
<td><textarea cols="38" rows="8" id="message_post" name="message_post"></textarea><br />255 Characters<br /><br /><input type="submit" id="submit" name="submit" value="Add" /> <input type="reset" id="reset" name="reset" value="clear" /></td>
</tr>
</table>
</p>
</form>
</body>
</html>
here is my guestbook_process.php code:
Code:
<html>
<head>
<title>Adding to Guestbook</title>
<script type="text/javascript">
<!--
function delayer()
{
window.location = "./guestbook.php"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 1000)">
<?php
require "connect.php";
$guest_name = mysql_escape_string($_POST['guest_name']);
$message_post = mysql_escape_string($_POST['message_post']);
if(empty($guest_name)||empty($message_post)) {
die('One or more fields are missing to enter your record to our guestbook.');
}
$query = mysql_query("INSERT INTO
guestbook(messageID,guest_name,message_post)
VALUES('','$guest_name','$message_post');");
echo "Thank you for adding to our guestbook. You will be redirected to the guestbook page in 1 seconds.";
mysql_close($connection);
?>
</body>
</html>
My guestbook database is defined as follows
guestbook(messageID,guest_name,message_post)