...

View Full Version : Page forwarding



Squintz
12-17-2002, 06:32 PM
Im not sure of any other way to solve my problem other than using some sort of page forwarding. I am creating a php page and i have the user submit a form... the form updates a data base and i want the page to goto my main page once the for has been submitted...

what is the HTML or javascript code for forwarding a user to another page imediatly... No Delay

beetle
12-17-2002, 06:34 PM
Uhh, why not let PHP do that?
<?php
/*
Handle form stuff here
*/
header("Location: index.php"); // Or whatever page is appropriate
?>

Squintz
12-17-2002, 06:52 PM
iv tried that but i getting a error on my page that says header already set let me paste some code...



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<?php
$server = "localhost";
$user = "****";
$password = "****";
$dbname = "contest";
$database_server = mysql_connect("$server", "$user", "$password");
mysql_select_db("$dbname", $database_server);
?>
<?
if ($submit) {

/* Maak SQL-query */
$sql = "INSERT INTO Contest(Contest_ID, Description, Title, StopDate) VALUES ('', '$Description', '$Title', '$StopDate')";
mysql_query($sql);

header("location: http://www.cbeginnersunited.com/contestadmin.php");
}
?>

<head>
<title>Add Contest - C Beginners United</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

Squintz
12-17-2002, 06:58 PM
here is my error

Warning: Cannot add header information - headers already sent by (output started at /home/domainwe/public_html/addcontest.php:3) in /home/domainwe/public_html/addcontest.php on line 18

Nightfire
12-17-2002, 07:12 PM
<?php
$server = "localhost";
$user = "****";
$password = "****";
$dbname = "contest";
$database_server = mysql_connect("$server", "$user", "$password");
mysql_select_db("$dbname", $database_server);

if ($submit) {

/* Maak SQL-query */
$sql = "INSERT INTO Contest(Contest_ID, Description, Title, StopDate) VALUES ('', '$Description', '$Title', '$StopDate')";
mysql_query($sql);

header("location: http://www.cbeginnersunited.com/contestadmin.php");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Add Contest - C Beginners United</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">


header() has to be sent before anything is parsed in the browser - that includes doctype declarations.

brothercake
12-17-2002, 07:20 PM
But why the DOCTYPE and HTML ? You're not displaying anything, so why add any HTML into the page at all? Taking it all out would solve the problem.



<?php
$server = "localhost";
$user = "****";
$password = "****";
$dbname = "contest";
$database_server = mysql_connect("$server", "$user", "$password");
mysql_select_db("$dbname", $database_server);

if ($submit) {

/* Maak SQL-query */
$sql = "INSERT INTO Contest(Contest_ID, Description, Title, StopDate) VALUES ('', '$Description', '$Title', '$StopDate')";
mysql_query($sql);

header("location: http://www.cbeginnersunited.com/contestadmin.php");
}

else {
...doctype and html could go here as error message
}
?>

Nightfire
12-17-2002, 07:46 PM
Oops, I should've picked up on that. Don't forget to change

header("location: <a href="http://www.cbeginnersunited.com/contestadmin.php" target="_blank">http://www.cbeginnersunited.com/contestadmin.php</a>");

to


header("location: http://www.cbeginnersunited.com/contestadmin.php");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum