php - Trying to prevent form re-submission upon refresh, can't modify header information -



php - Trying to prevent form re-submission upon refresh, can't modify header information -

i'm trying create page redirect same page avoid resending same form information. however, using header('location: guestbook.php'); gives me error:

warning: cannot modify header info - headers sent (output started @ /test/guestbook.php:1) in /test/guestbook.php on line 29

i'm not sure if i'm putting header in right place, i'm not extremely familiar using it:

<?php $gb_str = ""; // $gb_str string we'll append entries $pgetitle = "view , sign guestbook"; // if form submitted, insert db if (!empty($http_post_vars["submit"])) { // initiate vars $dbhost = ; $dbuser = ; $dbpass = ; $dbdatabase = ; $li = mysql_connect($dbhost, $dbuser, $dbpass) or die("could not connect"); mysql_select_db($dbdatabase, $li) or die ("could not select db"); $name = mysql_real_escape_string($http_post_vars["name"]); $email = mysql_real_escape_string($http_post_vars["email"]); $comment = mysql_real_escape_string($http_post_vars["comment"]); $date = date("y-m-d h:i:s"); $gb_query = "insert entries values(0, '$name', '$email', '$comment', '$date')"; mysql_query($gb_query); $res = mysql_affected_rows(); // see if insert successful or not if($res > 0) { $ret_str="your guestbook entry added!"; header('location: guestbook.php'); exit(); // end request } else { $ret_str = "there problem guestbook entry. please seek again."; } // append success/failure message $gb_str .= "<span class=\"ret\">$ret_str</span><br>"; mysql_close(); } ?>

you have bom or regular spaces in origin of file. remove them

php

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -