0

when we open registration webpage, an empty data gets inserted into database as well as on browser refresh. we have tried:

header("Location: addcandidate.php");
exit(0);

we have tried to put this code after all $_POST values and also at beginning of page. we are getting error as:`Cannot modify header information - headers already sent

        $addcandidate1=$_POST['candi_a_fname'];
        $addcandidate2=$_POST['candi_a_lname'];`
        header("Location: addcandidate.php");
        exit(0);

        mysql_connect('localhost','root','') or die(mysql_error());
        echo "connected"; 

        mysql_select_db('talent') or die(mysql_error());
        echo "database selected"; 

        $error = NULL;
        if (!$error) 
        {
            mysql_query("insert into candidate(cand_fname,cand_lname) values ('$addcandidate1','$addcandidate2')") or die(mysql_error());

            echo 'alert("Your Data Has Been Successfully Inserted ! Thank    You")';

        }
Code Sniper
  • 77
  • 1
  • 9

1 Answers1

0

You can add :

if($_POST['submit']) {
//your code
}

to run it only when the form has been submit. You should also stop using mysql_ methods, and go for PDO to use prepared statement.

xNeyte
  • 612
  • 4
  • 18