General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old July 31st, 2002, 12:19 AM
adrian adrian is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old July 31st, 2002, 12:49 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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?

Reply With Quote
  #3  
Old July 31st, 2002, 12:05 PM
adrian adrian is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old July 31st, 2002, 07:05 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
try using meta tags?
<META HTTP-EQUIV="refresh" content="0;URL=index.php">

Reply With Quote
  #5  
Old August 2nd, 2002, 12:44 PM
adrian adrian is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks again Ben. That did the trick.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Redirect to new page after form submit


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway