PHP and the HEADER function (to relocate)
Ok, I was trying to use the HEADER function in PHP (to move the visitor to another page)...
after adding the data from my form into my guestbook table, I wanted to go back to the guestbook page. The code is as follows:
THIS IS ALL THE CODE THAT IS ON THE PAGE....
<?php
$dbcnx = @mysql_connect("xxxx", "xxxx", "xxxx");
if (!$dbcnx) {
echo( "<P>Unable to connect to the server at this time.</P>" );
exit();
}
if (! @mysql_select_db("xxxx") ) {
echo ("<P>Unable to locate the guestbook database.</P>");
exit();
}
if ("SUBMIT" == $submitmessage) {
$sql = "INSERT INTO guestbook SET " .
"name='$name', " .
"city='$city', " .
"state='$state', " .
"country='$country', " .
"message='$message', " .
"date=curDATE()";
}
if (mysql_query($sql)) {
header("Location: [url]http://www.keithlubrant.com/guestbook");[/url]
}
?>
Then I get this error:
Cannot add more header information - the header was already sent (header information may be added only before any output is generated from the script - check for text or whitespace outside PHP tags, or calls to functions that output text) in verify.php3 on line 170
I just need somebody to show me the right way to use the header function. I know that nothing can be sent before it, but I still cannot get it to work.
Thanks in advance,
Keith
Gil posted this at 21:01 — 17th December 2000.
They have: 103 posts
Joined: Apr 1999
If you haven't gotten it to work by now, you could always use some basic Javascript. I don't see anything wrong with the code below, but you might want to run the program from the command line just so you could see all the output..
<script language="Javascript">
<!--
location.href="http://www.keithlubrant.com/guestbook"
//-->
</script>
Gil Hildebrand, Jr.
Internet Consultant
New Orleans, LA
Mark Hensler posted this at 03:28 — 18th December 2000.
He has: 4,048 posts
Joined: Aug 2000
quick Q:
shouldn't this be in the 'Other Scripting Languages Help Forums'?
make sure you don't have newlines and spaces. the very first thing in your file should be <?, then you may put all the newlines you want.
example:
<?
/*
this example works
*/
header("Location: http://www.me.com");
?>
<?
/*
this example doesn't work
notice the newlines at the top?
that's all it takes
*/
header("Location: http://www.me.com");
?>
another this you could do... include() the other page at the bottom of this one. It's sorta like sending them to that page, but not really. Know what I mean?
Good Luck,
Mark Hensler
If there is no answer on Google, then there is no question.
Peter J. Boettcher posted this at 13:41 — 18th December 2000.
They have: 812 posts
Joined: Feb 2000
keith,
I'm moving this to the "Other Scripting Languages" forum. As for your problem, make sure you haven't started processing (displaying) any information on the handler page, since the second you do that you can't send any more header information.
PJ | Are we there yet?
pjboettcher.com
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.