|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Redirect to new page after form submit
I'm trying to redirect visitors to a new page after they click on the submit button of a form but keep getting this error
Warning: Cannot add header information - headers already sent by (output started at /usr/home/xxxxxxxx_com/public_html/guestbook2.php:1) in /usr/home/xxxxxxxx_com/public_html/guestbook2.php on line 65 my script looks like this <? if ($_POST['enter_data']){ $date=date("Y-m-d"); $database_name = "xxxxx"; $dbh = mysql_connect("localhost","xxxxxx","xxxxx"); if (!mysql_select_db($database_name)) { echo "Can't Select $database_name"; } $sql = "insert into guestbook (date, name, country, email, comments) values ('$date', '$name', '$country', '$email', '$comments')"; $res = mysql_query($sql,$dbh); if (!$res) { echo mysql_errno().": ".mysql_error ().""; return 0; } header("Location:http://www.xxxxxxx.com/viewguestbook2.php"); exit; } ?> line 65 is the header line header("Location:http://www.xxxxxxx.com/viewguestbook2.php"); Any help on where i am going wrong would be much appreciated. Thanks. |
|
#2
|
|||
|
|||
|
this is because the headers have already been sent!
make sure the VERY first charcters in your php file is <?php make sure their isnt any whitespace, or carrage returns, otherwise you'll get errors. also if you try that and your still having problems try removing these lines echo "Can't Select $database_name"; and echo mysql_errno().": ".mysql_error ().""; as it maybe outputting for some reason? |
|
#3
|
|||
|
|||
|
Thanks for your reply Ben. I did everything you said but am still getting the same error.
Does anyone know of another way i can auto redirect to another page after the submit button has been pressed. I do not need to pass across any values or variables. The first script is just a guest book entry and then when the submit button is pressed i just want it to auto redirect to the view guestbook script. Thanks for you time. Hope someone can help. |
|
#4
|
|||
|
|||
|
try using meta tags?
<META HTTP-EQUIV="refresh" content="0;URL=index.php"> |
|
#5
|
|||
|
|||
|
Thanks again Ben. That did the trick.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Redirect to new page after form submit |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|