I'm using php4 and this is my code for a guest book:
<?php
/* Connecting, selecting database */
$link = mysql_connect("localhost", "root", "XXX")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("guest") or die("Could not select database");
$username = $_POST['name'];
$message = $_POST['message'];
/* Performing SQL query */
$query = "INSERT INTO guest VALUES ('$username', '$message')";
$query2 = "SELECT * FROM guest";
mysql_query($query) or die("Query failed : " . mysql_error());
$result = mysql_query($query2) or die("Query failed : " . mysql_error());
/* Printing results in HTML */
echo "<table border='3' width = '70%'>\n";
echo "\t<tr>\n";
echo "\t\t<td>UserName</td>\n";
echo "\t\t<td>Message</td>\n";
echo "\t</tr>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
?>
http://dfownz.zapto.org/index.php for the guestbook
The problem is: Each time i refresh the page it resends the data into the mysql database....i don't want that to happen. Also, it adds more cell spacing after refreshing the page (just check it out, refresh the page a lot).
Thanks,
DF