hi i am a newbie php programmer and i am currently working on something but is having problems with. What am trying to do is create a simple addressbook, i am able to post the data on the DB however when i refresh the page the data gets reposted.

Here is the code i have:

<?php session_start();
$_SESSION['values']= array($_POST['name'], $_POST['bday'], $_POST['addr'], $_POST['phone'], $_POST['email']);
if(isset($_POST['send'])){
	include("connect.php");
	include("insert.php");
	insert();
	echo "$_POST[name] ". 'had been added to your address book.';
	if($_SESSION['values'] != NULL){
						unset($_SESSION['values']);
					   }
	}
?>

Hope you can help me with this, thanks!!!

    One way to handle this is to use a session. On the page where you output the form where they can fill in the form fields and submit, create some variable in the session - e.g. $_SESSION['address_form'] = 1; .

    Then, in your code above that processes incoming POST data, you could do:

    if(isset($_POST['send'], $_SESSION['address_form'])){ 
        unset($_SESSION['address_form']);

    That way, the POST'ed data will only be processed once; in order to re-submit the values for processing, they'd have to visit the page with your form again so that the session variable is set again.

      Maybe this is can help you, demo
      http://www.dynamicdrive.com/dynamicindex11/submitonce.htm

      I have similar problem and also looking for some solutions for this.

      I have a select menu with few options and on submit I want continue to choose new option and submit if necessary. This select menu start some functions for updating/deleting posts in database on submit but also on page refresh. By mistake maybe.

      Anyone have solutions for this?

        After submitting your form and get data redirect it on other page using redirect() or Header("Location: You page address") function.

          Problem is that i also have some report that printing out some info after submit and when script is dune.

          I want that messages and with redirect or header() links back that messages is gone.

            There are a couple of ways to get round this if you can't use header redirects.

            Firstly, just before you insert the data, check to see that the same data wasn't just entered.

            Secondly, you could use a compound unique index on the fields in the database. That way, an error is returned if you try to insert the same data again. You can use the @ directive to ignore the error, or do something with it in your code.

              ei guys thanks a bunch for the reply helped me a lot... i used header() on my code and it worked for me... i haven't tried your solution bradgrafelman but i would like to do it also using that manner...

                Write a Reply...