Jump to content

[SOLVED] Submitting a form - to redirect to another page


Recommended Posts

<form action=<?php echo $_SERVER[ 'PHP_SELF']; ?> method="post">
<frameset>
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="aname" value="<?php echo $aname; ?>" /> <?php if($errorID==1) echo "* $errorMsg"; ?></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" value="<?php echo $address; ?>" /> <?php if($errorID==2) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td>Post Code:</td>
<td><input type="text" name="post_code" value="<?php echo $post_code; ?>" /> <?php if($errorID==3) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" /></td>
</tr>
</table>
</frameset>
</form>

<?php
if (isset($errorID) && $errorID==0)
{
header ("Location: index.php");
}
?>

 

after the form coding, i want the page to be directed to another .php page, i tried using the header finction but it doesnt seam to work, is there something i am doing wrong.

 

please help

 

thank you

is there something i am doing wrong

 

Yes, you are sending output prior to calling header. Try...

 

<?php if ($_SERVER['REQUEST_METHOD'] == "GET") {?>
<form action=<?php echo $_SERVER[ 'PHP_SELF']; ?> method="post">
<frameset>
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="aname" value="<?php echo $aname; ?>" /> <?php if($errorID==1) echo "* $errorMsg"; ?></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" value="<?php echo $address; ?>" /> <?php if($errorID==2) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td>Post Code:</td>
<td><input type="text" name="post_code" value="<?php echo $post_code; ?>" /> <?php if($errorID==3) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" /></td>
</tr>
</table>
</frameset>
</form>

<?php
} else {
  if (isset($errorID) && $errorID == 0) {
    header ("Location: index.php");
  }
}
?>

Try this:

 

<?php 
if (isset($_POST['submit'])){
  if (isset($errorID) && ($errorID == 0)) {
    header ("Location: index.php");
  }
} else {
?>
<form action=<?php echo $_SERVER[ 'PHP_SELF']; ?> method="post">
<frameset>
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="aname" value="<?php echo $aname; ?>" /> <?php if($errorID==1) echo "* $errorMsg"; ?></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" value="<?php echo $address; ?>" /> <?php if($errorID==2) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td>Post Code:</td>
<td><input type="text" name="post_code" value="<?php echo $post_code; ?>" /> <?php if($errorID==3) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" /></td>
</tr>
</table>
</frameset>
</form>
<?PHP } ?>

<?php
if($_POST) //if page has been submitted
{
$errorID=0;
$aname=$_POST[ 'aname'];
$address=$_POST[ 'address'];
$post_code=$_POST[ 'post_code'];

  if(trim($aname) =="") //Is the value empty?
{
  $errorID=1; $errorMsg="Name cannot be an empty value!";
}
  elseif(trim($address) =="") //Is the value empty?
{
  $errorID=2; $errorMsg="Address cannot be an empty value!";
}
  elseif(trim($post_code) =="") //Is the value empty?
{
  $errorID=3; $errorMsg="Post Code cannot be an empty value!";
}
}      
?>
<!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"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="head" -->
<link rel="stylesheet" type="text/css" href="styles.css" media="all"/>
<meta http-equiv="Content-Type"content="text/html;charset=iso-8859-1"/>
<title>Angel Estates</title>
<!-- InstanceEndEditable -->
</head>

<body>

<div class="container">
<div class="shadow">
<div class="main">
<div class="banner">
<div class="title">Angel Estates</div> <!-- title -->
</div>
<!-- banner -->

<div class="menu_container">
<div class="menu"><!-- InstanceBeginEditable name="menu" -->
<ul class="menu">
  <li><a href="index.php"><span>Home</span></a></li>
  <li><a href="search.php"><span>Search</span></a></li>
  <li><a href="agents.php" class="active"><span>Agents</span></a></li>
  <li><a href="tenants.php"><span>Tenants</span></a></li>
  <li><a href="properties.php"><span>Properties</span></a></li>
</ul>
<!-- InstanceEndEditable --></div> 
<!-- menu -->
</div> <!--menu_container-->

<div class="content">
<div class="left_panel">
  <!-- InstanceBeginEditable name="left content" -->
<p><a href="agents_insert.php" class="link" class="link_hover">Insert Agent Details</a></p>

<p><a href="#" class="link" class="link_hover">Update Agent Details</a></p>

<p><a href="#" class="link" class="link_hover">Delete Agent Details</a></p>
  <!-- InstanceEndEditable --></div>
<!-- left_panel -->
<div class="right_content">
  <!-- InstanceBeginEditable name="right content" -->
<p class="sub_title">Insert Agent Details</p>
<?php 
if (isset($_POST['submit'])){
  if (isset($errorID) && ($errorID == 0)) {
    header ("Location: index.php");
  }
} else {
?>
<form action=<?php echo $_SERVER[ 'PHP_SELF']; ?> method="post">
<frameset>
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="aname" value="<?php echo $aname; ?>" /> <?php if($errorID==1) echo "* $errorMsg"; ?></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" value="<?php echo $address; ?>" /> <?php if($errorID==2) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td>Post Code:</td>
<td><input type="text" name="post_code" value="<?php echo $post_code; ?>" /> <?php if($errorID==3) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" /></td>
</tr>
</table>
</frameset>
</form>
<?PHP } ?>
<!-- InstanceEndEditable --></div>
<!-- right_content -->
</div><!-- content -->
</div><!-- main -->
</div><!-- shadow -->
</div><!-- container -->

</body>
<!-- InstanceEnd --></html>

 

this is the error

 

 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\EstateAgent\agents_insert.php:28) in C:\xampp\htdocs\EstateAgent\agents_insert.php on line 72

 

Put your header above any HTML display.

 

<?php
if($_POST['submit']) //if page has been submitted
{
$errorID=0;
$aname=$_POST[ 'aname'];
$address=$_POST[ 'address'];
$post_code=$_POST[ 'post_code'];

  if(trim($aname) =="") //Is the value empty?
{
  $errorID=1; $errorMsg="Name cannot be an empty value!";
}
  elseif(trim($address) =="") //Is the value empty?
{
  $errorID=2; $errorMsg="Address cannot be an empty value!";
}
  elseif(trim($post_code) =="") //Is the value empty?
{
  $errorID=3; $errorMsg="Post Code cannot be an empty value!";
}

  if ($errorID == 0) {
    header ("Location: index.php");
  }
}      
?>
<!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"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="head" -->
<link rel="stylesheet" type="text/css" href="styles.css" media="all"/>
<meta http-equiv="Content-Type"content="text/html;charset=iso-8859-1"/>
<title>Angel Estates</title>
<!-- InstanceEndEditable -->
</head>

<body>

<div class="container">
<div class="shadow">
<div class="main">
<div class="banner">
<div class="title">Angel Estates</div> <!-- title -->
</div>
<!-- banner -->

<div class="menu_container">
<div class="menu"><!-- InstanceBeginEditable name="menu" -->
<ul class="menu">
  <li><a href="index.php"><span>Home</span></a></li>
  <li><a href="search.php"><span>Search</span></a></li>
  <li><a href="agents.php" class="active"><span>Agents</span></a></li>
  <li><a href="tenants.php"><span>Tenants</span></a></li>
  <li><a href="properties.php"><span>Properties</span></a></li>
</ul>
<!-- InstanceEndEditable --></div>
<!-- menu -->
</div> <!--menu_container-->

<div class="content">
<div class="left_panel">
  <!-- InstanceBeginEditable name="left content" -->
<p><a href="agents_insert.php" class="link" class="link_hover">Insert Agent Details</a></p>

<p><a href="#" class="link" class="link_hover">Update Agent Details</a></p>

<p><a href="#" class="link" class="link_hover">Delete Agent Details</a></p>
  <!-- InstanceEndEditable --></div>
<!-- left_panel -->
<div class="right_content">
  <!-- InstanceBeginEditable name="right content" -->
<p class="sub_title">Insert Agent Details</p>
<form action=<?php echo $_SERVER[ 'PHP_SELF']; ?> method="post">
<frameset>
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="aname" value="<?php echo $aname; ?>" /> <?php if($errorID==1) echo "* $errorMsg"; ?></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" value="<?php echo $address; ?>" /> <?php if($errorID==2) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td>Post Code:</td>
<td><input type="text" name="post_code" value="<?php echo $post_code; ?>" /> <?php if($errorID==3) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="submit" /></td>
</tr>
</table>
</frameset>
</form>
<?PHP } ?>
<!-- InstanceEndEditable --></div>
<!-- right_content -->
</div><!-- content -->
</div><!-- main -->
</div><!-- shadow -->
</div><!-- container -->

</body>
<!-- InstanceEnd --></html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.