coolguyraj
03-10-2009, 08:22 AM
Hi,
I have a form to create a new location.It updates the new record to the DB but it idplays blank page with error message.
"Cannot modify header information - headers already sent by"
Could some help me to correct my code to get rid of the error.
My main aim is to display html_location.php after the new record is added.
<?php
$building = $_REQUEST['building'];
$submit = $_REQUEST['submit'];
//Check if form has been submitted
if ($submit==1){
//set variables of from form
$building = $_REQUEST['building'];
//Error check
if (empty($building)){
$message ="The building name is required.<br/>";
}
//If the are no errors, insert the data to the database.
if (empty($message)){
$con = mysql_connect('test', 'user', 'new');
mysql_select_db("test", $con);
//SQL to insert new building
$query = "INSERT INTO buildings (Name) VALUES (upper('$building'))";
mysql_query($query) or die('Error, insert query failed');
mysql_close();
//Return the user to the project's page
header("Locatation:html_location.php");
exit;
}?>
<?php
}
?>
<head>
<title>Building - New</title>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" class="head">Location - New Building</td>
<td align="right" valign="bottom" class="text"> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="4" width="100%">
<tr>
<td width="114" class="activetab">Add New Bulding</td>
<td class="nontab"> </td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<?php if (!empty($message)) {?>
<tr>
<td class="Text" colspan="2"><?php echo $message;?></td>
</tr>
<?php } ?>
<form name="building_form" method="post" action="">
<input type="hidden" name="submit" value="1" >
</br>
<tr>
<td align="left" class="text">Building Name</td>
<td align="left" class="text">
<input class="inputfield" name="building" id="build" size="25" ></td>
</tr> <tr><td colspan="2" align="left"
class="text"> </td></tr>
<tr style="height: 100%; vertical-align: bottom;">
<td colspan="2" align="right">
<input type="submit" value="Save" class="form"> </td>
</tr>
</table>
</FORM>
</body>
I have a form to create a new location.It updates the new record to the DB but it idplays blank page with error message.
"Cannot modify header information - headers already sent by"
Could some help me to correct my code to get rid of the error.
My main aim is to display html_location.php after the new record is added.
<?php
$building = $_REQUEST['building'];
$submit = $_REQUEST['submit'];
//Check if form has been submitted
if ($submit==1){
//set variables of from form
$building = $_REQUEST['building'];
//Error check
if (empty($building)){
$message ="The building name is required.<br/>";
}
//If the are no errors, insert the data to the database.
if (empty($message)){
$con = mysql_connect('test', 'user', 'new');
mysql_select_db("test", $con);
//SQL to insert new building
$query = "INSERT INTO buildings (Name) VALUES (upper('$building'))";
mysql_query($query) or die('Error, insert query failed');
mysql_close();
//Return the user to the project's page
header("Locatation:html_location.php");
exit;
}?>
<?php
}
?>
<head>
<title>Building - New</title>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" class="head">Location - New Building</td>
<td align="right" valign="bottom" class="text"> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="4" width="100%">
<tr>
<td width="114" class="activetab">Add New Bulding</td>
<td class="nontab"> </td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<?php if (!empty($message)) {?>
<tr>
<td class="Text" colspan="2"><?php echo $message;?></td>
</tr>
<?php } ?>
<form name="building_form" method="post" action="">
<input type="hidden" name="submit" value="1" >
</br>
<tr>
<td align="left" class="text">Building Name</td>
<td align="left" class="text">
<input class="inputfield" name="building" id="build" size="25" ></td>
</tr> <tr><td colspan="2" align="left"
class="text"> </td></tr>
<tr style="height: 100%; vertical-align: bottom;">
<td colspan="2" align="right">
<input type="submit" value="Save" class="form"> </td>
</tr>
</table>
</FORM>
</body>