使用PHP和MySQL保存数据后,无法在标题内设置URL

I have an issue.I am trying to set URL inside header after save data into DB so that it will not auto save again at each time of page reload.I am explaining my code below.

$result = $dbobj->savePincode($newCustomerobj);
if($result == 1)
    {

        $msg='3';
    }
    else
    {
        $msg='2';
    }

In this case after data successfully saved ,some value is returning to the the variable result then it is matching inside if condition and get into the below function.

messagestatus(<?php echo $msg ?>);
function messagestatus(st)
{
    switch(st)
    {   
        case 1:
        {
            alert("Data Updated Successfully.");
            <?php header("location:http://localhost/backend/pincode.php"); ?>
            break;
        } 
        case 2:
        {
            alert("This user id already exist..");
            break;
        } 
        case 3:
        {
            alert("Data Saved Successfully");
            <?php header("location:http://localhost/backend/pincode.php" ?>
            break;
        }
        case 4:
        {
            alert("Data deleted Successfully");
            <?php header("location:http://localhost/backend/pincode.php"); ?>
            break;
        }
    }
}

Here i am setting the header so that it will return to the mail page after alert message.But its not happening like that as result it is inserting data again and again at each time of page reload.Here i need to prevent that.Please help me.