Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    93
    Thanks
    5
    Thanked 0 Times in 0 Posts

    PHP redirection does not work

    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.


    Code:
    <?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">&nbsp;</td>
    </tr>
    
    <tr>
    <td>&nbsp;</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">&nbsp;</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">&nbsp;</td></tr>
    <tr style="height: 100%; vertical-align: bottom;">
    <td colspan="2" align="right">
    <input type="submit" value="Save" class="form">&nbsp;&nbsp;</td>
    </tr>
    
    </table>
    </FORM>
    </body>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Please post the exact error message you get.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Nov 2005
    Posts
    93
    Thanks
    5
    Thanked 0 Times in 0 Posts

    exact error message

    Warning: Cannot modify header information - headers already sent by (output started at /usr/share/html_view_newbuilding.php:2) in /usr/share/html_view_newbuilding.php

  • #4
    Regular Coder
    Join Date
    Nov 2004
    Location
    Edinburgh, SCO
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This usually means that you have printed something to the screen already. Either by using echo or similar.

    Is the code you sent the entire php file, or is it included in some other file?

  • #5
    New Coder
    Join Date
    Nov 2005
    Posts
    93
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Complete code

    Thats the complete code. i am no printing anything before or using any echo statement.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Looks like the same file.
    This is a little unusual though, generally pre-opening output is generated at line 1. I'm thinking its some byte order markings in there, so you may want to consider using a standard notepad / wordpad instead of the IDE you're currently using.
    To fix, open the file html_view_newbuilding.php in notepad and save it back using save as ensuring that ANSI is selected as you're encoding type.
    Try that, post back you're results.

    Edit:
    Oh yes, if you see anything before the <?php, make sure thats removed as well. This includes any whitespace.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    coolguyraj (03-10-2009)

  • #7
    New Coder
    Join Date
    Nov 2005
    Posts
    93
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Thanks

    That really worked.....

    Thanks for all the help

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You're welcome.
    Try to find a new editor to use. Any basic editor will work (notepad, vim, phpedit, etc), or IDE specifically developed to handle PHP to get around future troubles with the BOM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •