theprophet
12-21-2004, 02:07 AM
The problem I am having is when I post to my guestbook I get what I put in but if i refresh the page it sends the information again. So what I want to figure out is how to prevent this. Here is a example of my code
<?php
$name = $_GET["txt_name"];
$len = strlen($name);
if($len > 0)
{
$email = $_GET["txt_email"];
$comment = $_GET["txt_comment"];
$date = time();
$query = "INSERT INTO guestbook (autoID, name, email, comment, date_auto)
VALUES (NULL, '$name', '$email', '$comment', '$date')";
mysql_query($query, $connection) or die (mysql_error());
}
?>
<html>
<head>
<title>Welcome to Keiths Guestbook</title>
</head>
<body>
<center>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="GET">
<font face="arial" size="1">
Name: <input type="text" name="txt_name">
Email: <input type="text" name="txt_email"><br><br>
Comment: <br>
<textarea style="width: 75%" rows="10" name="txt_comment"></textarea>
<center><input type="submit" value="Submit"></center>
</font>
<table bgcolor="#AAAAAA" border="0" width="75%" cellapceing="1" cellpading="2">
<?php
$query = "Select * FROM guestbook ORDER BY date_auto";
$result = mysql_query($query, $connection);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$name = mysql_result($result, $i, "name");
$email = mysql_result($result, $i, "email");
$email_len = strlen($email);
$comment = mysql_result($result, $i, "comment");
$comment = nl2br($comment);
$date = mysql_result($result, $i, "date_auto");
$show_date = date("H:i:s m/d/Y", $date);
if ($i % 2)
{
$bg_color="#EEEEEE";
}
else
{
$bg_color="#E0E0E0";
}
echo '
<tr>
<td width="100%" bgcolor="'.$bg_color.'">
<font face="arial" size="2">';
if ($email_len > 0)
{
echo '<b>Name:</b> <a href="mailto:'.$email.'">'.$name.'</a>';
}
else
{
echo '<b>Name:</b>'.$name;
}
echo '
<br>
<b>Comment:</b> '.$comment.'
</font>
<td>
<td width="1%" valign="top" nowrap bgcolor="'.$bg_color.'">
<font face="arial" size="2">
<b>Date:</b> '.$show_date.'
</font>
</td>
</tr>
';
}
?>
</table>
</center
</body>
</html>
<?php
$name = $_GET["txt_name"];
$len = strlen($name);
if($len > 0)
{
$email = $_GET["txt_email"];
$comment = $_GET["txt_comment"];
$date = time();
$query = "INSERT INTO guestbook (autoID, name, email, comment, date_auto)
VALUES (NULL, '$name', '$email', '$comment', '$date')";
mysql_query($query, $connection) or die (mysql_error());
}
?>
<html>
<head>
<title>Welcome to Keiths Guestbook</title>
</head>
<body>
<center>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="GET">
<font face="arial" size="1">
Name: <input type="text" name="txt_name">
Email: <input type="text" name="txt_email"><br><br>
Comment: <br>
<textarea style="width: 75%" rows="10" name="txt_comment"></textarea>
<center><input type="submit" value="Submit"></center>
</font>
<table bgcolor="#AAAAAA" border="0" width="75%" cellapceing="1" cellpading="2">
<?php
$query = "Select * FROM guestbook ORDER BY date_auto";
$result = mysql_query($query, $connection);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$name = mysql_result($result, $i, "name");
$email = mysql_result($result, $i, "email");
$email_len = strlen($email);
$comment = mysql_result($result, $i, "comment");
$comment = nl2br($comment);
$date = mysql_result($result, $i, "date_auto");
$show_date = date("H:i:s m/d/Y", $date);
if ($i % 2)
{
$bg_color="#EEEEEE";
}
else
{
$bg_color="#E0E0E0";
}
echo '
<tr>
<td width="100%" bgcolor="'.$bg_color.'">
<font face="arial" size="2">';
if ($email_len > 0)
{
echo '<b>Name:</b> <a href="mailto:'.$email.'">'.$name.'</a>';
}
else
{
echo '<b>Name:</b>'.$name;
}
echo '
<br>
<b>Comment:</b> '.$comment.'
</font>
<td>
<td width="1%" valign="top" nowrap bgcolor="'.$bg_color.'">
<font face="arial" size="2">
<b>Date:</b> '.$show_date.'
</font>
</td>
</tr>
';
}
?>
</table>
</center
</body>
</html>