i make a website in php ,in whichi give topic on topic user give comment ,

problem is that when user give comment ,after giving comment when we refresh the page ,

the browser ask a question resend and cancel in dialogue box sir plz tell me how can i remove this problem

    <?php  

                echo $usedatafte['un'].' says';


          ?>
        <form action="" method="post"  name="myform" id="myform" > 
        <input type="hidden" name="c1" value=<?php echo $usedatafte['user_id']; ?> /> 
        <input type="hidden" name="c2" value=<?php echo $topicdatafte['ht_id'];      ?>  /> 
        <div id='myform_c3_errorloc' class="error_strings"></div>
        <textarea type="comment" name="c3" style=" width:100%; height:135px; "/></textarea> 
        <div style="margin-top:10px;" align="right" >
        <input type="submit" name="c4" value="" style="background-image:url(img/jpg/submit.png); background-color:#FFF; border:none; width:100px; height:42px; color:#FFF; cursor: pointer;
cursor: hand; "/>
        </div>
        </form>


<?php
if(isset($_POST["c4"]))
{
    $insert=mysql_query("INSERT INTO hero_topic_c(hero_topic_c_userid,hero_topic_c_t_id,hero_topic_c_cm)values('$_POST[c1]','$_POST[c2]','$_POST[c3]')");
    if($insert)
    {
        echo "" ;
    }
    else
    die ("an error") ;

}


?>

move your $_POSt proccessing to the very top of the page then tell the page to redirect to itself after posting.

<?php
if(isset($_POST["c4"])){
    $insert=mysql_query("INSERT INTO hero_topic_c(hero_topic_c_userid,hero_topic_c_t_id,hero_topic_c_cm)values('$_POST[c1]','$_POST[c2]','$_POST[c3]')");
    if($insert){
        header("Location: thesamepage.php");
        echo "";
    }else{
        die ("an error");
    }
}
?>

The reason the browser is asking is cause you have submitted post data to get to that page, so the browser is asking do you want to send this data again? as it could be personal/cause duplicate orders the browser doesn't do it automatically but at the same time could make the page display differently, such as a search page, so asks you.

Redirecting will mean the browser last made a GET request to retrieve the page and will have no need to ask.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.