Page 1 of 1
Re: Keeps inserting to mysql on browser reload
Posted: Sat Dec 17, 2011 9:15 am
by phpHappy
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
Re: Keeps inserting to mysql on browser reload
Posted: Tue Dec 20, 2011 1:40 pm
by Amanda1998
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
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>
And here on >> chat.php file, you do what you need to do with the data and at the end, you do
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" />';
?>