I know this should be easy but how do I redirect the user to a certain page after the form is submitted? My form page code is below - currently it only prints a message after form submission- instead I want the user to go to a page called databaseExample.php. Thank you very much.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Form Entry for Tournaments</title>
<style>
		#reg
		{
			font-family:"arial", "verdana";
			font-size:13px;			
		}
</style>

</head>

<body onload="document.forms[0].tournyName.focus()">
<?php include("menu.php"); ?>

<?php 

if (!isset($_POST['submit'])) { 
// form not submitted 
?> 

<form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
	<table border="0" id="reg">
  <tr>
    <td>Tournament Name:</td>
	<td><input type="text" name="tournyName" size="40"></td>
  </tr>
  <tr>
    <td>Tournament Date:</td>
	<td><input type="text" name="tournyDate" size="15"> Use this format: 2008-05-15</td>
  </tr>
  <tr>
    <td>Location:</td>
	<td><input type="text" name="Location" size="30"></td>
  </tr>
  <tr>
    <td>Purse:</td>
	<td><input type="text" name="Purse" size="7"></td>
  </tr>
  <tr>
    <td>Entry Fee:</td>
	<td><input type="text" name="entryFee" size="7"></td>
  </tr>
  <tr>
    <td colspan="2"><input type="submit" name="submit" value="Submit"> </td>
  </tr>

</table>
</form> 


<?php 
} 
else { 
// form submitted 
// set database server access variables: 
$host = "myHost";
$user = "user"; 
$pass = "pass"; 
$db = "test"; 

// get form input 
    // check to make sure it's all there 
    // escape input values for greater safety 
    $tournyName = empty($_POST['tournyName']) ? die ("ERROR: Enter a Tournament Name") : mysql_escape_string($_POST['tournyName']); 
	$tournyDate = empty($_POST['tournyDate']) ? die ("ERROR: Enter a Tournament Date") : mysql_escape_string($_POST['tournyDate']); 
    $Location = empty($_POST['Location']) ? die ("ERROR: Enter an Location") : mysql_escape_string($_POST['Location']);
	$Purse = empty($_POST['Purse']) ? die ("ERROR: Enter a Purse Amount") : mysql_escape_string($_POST['Purse']); 
	$entryFee = empty($_POST['entryFee']) ? die ("ERROR: Enter an Entry Fee Amount") : mysql_escape_string($_POST['entryFee']); 
    // open connection 
    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 

// select database 
mysql_select_db($db) or die ("Unable to select database!"); 

// create query 
$query = "INSERT INTO Tournament (tournyName, tournyDate, Location, Purse, entryFee) VALUES ('$tournyName', '$tournyDate', '$Location', '$Purse', '$entryFee')"; 

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 

// print message with ID of inserted record 
echo " A new record was inserted with an ID of ".mysql_insert_id();

// close connection 
mysql_close($connection); 
} 
?>







</body>
</html>

    Well, first you'd have to re-arrange your code. The easiest way to redirect someone would be via a [man]header/man call to send a 'Location' HTTP header.

    To output HTTP headers, however, you have to call the header() function before any data is outputted, thus you'd need to do the processing at the top of the script.

      Here is the form once submited displays that message for 5 seconds then goes to that other page:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
      <html xmlns="http://www.w3.org/1999/xhtml"> 
      <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
      <title>Form Entry for Tournaments</title> 
      <style> 
              #reg 
              { 
                  font-family:"arial", "verdana"; 
                  font-size:13px;             
      } </style> </head> <body onload="document.forms[0].tournyName.focus()"> <?php include("menu.php"); ?> <?php if (!isset($_POST['submit'])) { // form not submitted ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <table border="0" id="reg"> <tr> <td>Tournament Name:</td> <td><input type="text" name="tournyName" size="40"></td> </tr> <tr> <td>Tournament Date:</td> <td><input type="text" name="tournyDate" size="15"> Use this format: 2008-05-15</td> </tr> <tr> <td>Location:</td> <td><input type="text" name="Location" size="30"></td> </tr> <tr> <td>Purse:</td> <td><input type="text" name="Purse" size="7"></td> </tr> <tr> <td>Entry Fee:</td> <td><input type="text" name="entryFee" size="7"></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Submit"> </td> </tr> </table> </form> <?php } else { // form submitted // set database server access variables: $host = "myHost"; $user = "user"; $pass = "pass"; $db = "test"; // get form input // check to make sure it's all there // escape input values for greater safety $tournyName = empty($_POST['tournyName']) ? die ("ERROR: Enter a Tournament Name") : mysql_escape_string($_POST['tournyName']); $tournyDate = empty($_POST['tournyDate']) ? die ("ERROR: Enter a Tournament Date") : mysql_escape_string($_POST['tournyDate']); $Location = empty($_POST['Location']) ? die ("ERROR: Enter an Location") : mysql_escape_string($_POST['Location']); $Purse = empty($_POST['Purse']) ? die ("ERROR: Enter a Purse Amount") : mysql_escape_string($_POST['Purse']); $entryFee = empty($_POST['entryFee']) ? die ("ERROR: Enter an Entry Fee Amount") : mysql_escape_string($_POST['entryFee']); // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "INSERT INTO Tournament (tournyName, tournyDate, Location, Purse, entryFee) VALUES ('$tournyName', '$tournyDate', '$Location', '$Purse', '$entryFee')"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // print message with ID of inserted record echo " A new record was inserted with an ID of ".mysql_insert_id(); ?> <script language="javascript"> setTimeout("window.location = 'databaseExample.php';", 5000); </script> <?php // close connection mysql_close($connection); } ?> </body> </html>

      Or just to have it how you said:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
      <html xmlns="http://www.w3.org/1999/xhtml"> 
      <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
      <title>Form Entry for Tournaments</title> 
      <style> 
              #reg 
              { 
                  font-family:"arial", "verdana"; 
                  font-size:13px;             
      } </style> </head> <body onload="document.forms[0].tournyName.focus()"> <?php include("menu.php"); ?> <?php if (!isset($_POST['submit'])) { // form not submitted ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <table border="0" id="reg"> <tr> <td>Tournament Name:</td> <td><input type="text" name="tournyName" size="40"></td> </tr> <tr> <td>Tournament Date:</td> <td><input type="text" name="tournyDate" size="15"> Use this format: 2008-05-15</td> </tr> <tr> <td>Location:</td> <td><input type="text" name="Location" size="30"></td> </tr> <tr> <td>Purse:</td> <td><input type="text" name="Purse" size="7"></td> </tr> <tr> <td>Entry Fee:</td> <td><input type="text" name="entryFee" size="7"></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Submit"> </td> </tr> </table> </form> <?php } else { // form submitted // set database server access variables: $host = "myHost"; $user = "user"; $pass = "pass"; $db = "test"; // get form input // check to make sure it's all there // escape input values for greater safety $tournyName = empty($_POST['tournyName']) ? die ("ERROR: Enter a Tournament Name") : mysql_escape_string($_POST['tournyName']); $tournyDate = empty($_POST['tournyDate']) ? die ("ERROR: Enter a Tournament Date") : mysql_escape_string($_POST['tournyDate']); $Location = empty($_POST['Location']) ? die ("ERROR: Enter an Location") : mysql_escape_string($_POST['Location']); $Purse = empty($_POST['Purse']) ? die ("ERROR: Enter a Purse Amount") : mysql_escape_string($_POST['Purse']); $entryFee = empty($_POST['entryFee']) ? die ("ERROR: Enter an Entry Fee Amount") : mysql_escape_string($_POST['entryFee']); // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "INSERT INTO Tournament (tournyName, tournyDate, Location, Purse, entryFee) VALUES ('$tournyName', '$tournyDate', '$Location', '$Purse', '$entryFee')"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); header("location: databaseExample.php"); // close connection mysql_close($connection); } ?> </body> </html>

      Both of these was tested,

        bradmasterx wrote:

        Both of these was[sic] tested,

        ... and the second version failed (because what I suggested was re-ordering the code into a more logical format - do some processing first to determine if you even need to output HTML at all - so that a header() call would be possible)?

          Write a Reply...