Any reload of a page that accepts form data resends that data
$_POST "post" method isn't seen in a URL like $_GET "get" method but it is there and a reload has that data
insert if not exists
Keeps inserting to mysql on browser reload
Moderator: General Moderators
-
Amanda1998
- Forum Newbie
- Posts: 23
- Joined: Tue Dec 13, 2011 10:25 am
Re: Keeps inserting to mysql on browser reload
Each time you make a query to MySQL, you can give an >> exit(); (prevents continuous execution), and after inserting data you do a redirect:
This is your form.php
And here on >> chat.php file, you do what you need to do with the data and at the end, you do
This is your form.php
Code: Select all
<?php
if (isset($_POST['submit']))
{
ob_start();
include('chat.php');
ob_end_clean();
}
?>
<html bs goes here>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Message: <input type="text" name="message" />
<input type="submit" />
</form>
</html bs end here>
Code: Select all
<?php
/** blah, blah, your code **/
/** blah, blah, your code **/
/** and at the end **/
echo '<meta http-equiv="REFRESH" content="0; url=chat.php" />';
?>
Last edited by Amanda1998 on Tue Dec 20, 2011 1:45 pm, edited 2 times in total.