SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: HEADER Problem

  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I don't really understand this Header-staff. I have this script here:

    if ($status == "1") {
    HEADER ("Location: $Basis_R/culturo/ticket_e_eingabe1.php3");
    }
    if ($status == "2") {
    HEADER ("Location: $Basis_R/culturo/ticket_e_eingabe2.php3");
    }
    if($status == "3") {
    HEADER ("Location: $Basis_R/culturo/ticket_e_eingabe3.php3");
    }

    The Header-function worked fine in another skript, but not here. I want to send the user to different pages depending of the status, which I get from I database.
    Any idea?

  2. #2
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ..forgott to say, I get this error message :
    "Warning: Cannot add header information - headers already sent by ..(the location of the side).."

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't have any html or output or whitespace above your header calls php code is fine as long as it doesn't echo or print anything to the screen and whitespace inside the php tags is okay as well, just not outside the tags.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Could you let us know whats the value of the variable $Basic_R ?

    Please note, it is necessary to have a http:// infront

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually zhchua you don't need the http:// I suspect and am 99% sure the problem is whitespace above the header() call
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whitespace?

    Which whitespace. Sorry, I don't get it.

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    "Warning: Cannot add header information - headers already sent by ..(the location of the side).." 
    This error means a header() function or a cookie function was being called after the start of output to the screen. Output takes on many forms(ie. whitespace, html).

    The following examples will cause such an error to occur

    Sample page
    Starting on first line
    PHP Code:
    <html><head><body>
    <?
    header
    ("Location: somepage.php");
    ?>

    or
    Starting on first line
    See the first three lines are blank and they reside above the opening PHP tag so they are considered whitespace to php and will result in such an error.
    PHP Code:



    <?
    header
    ("Location: somepage.php");
    ?>
    <html><head><body>





    Hope that clears it up for you.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simply put, I still don't get it.. Now I'm having this problem :

    Code:
    <html>
    <body bgcolor=white>
    <center>
    	<font face="verdana" size=1>		
    		<b>Frozened Index Directory Administrator Add</b>
    		<br>
    		This is where current head administrators add new administrators to maintain the Frozened Network
    	</font>
    </center>
    <? 
    if ($submit == "Submit") {              // If form has been submitted
    	$errormsg = array();
    
    	#$emptyfields = 0;
    	
    	if ($username == "") {
    		$errormsg[] = "Please fill in your username";	
    	}
    	
    	if (!$real_name){
    		$errormsg[] = "Please fill in your Real Name";	
    	}
    	
    	if (!$email) {
    		$errormsg[] = "Please fill in your email address";	
    	}
    	
    	if (!$password) {
    		$errormsg[] = "Please fill in your password";	
    	}
    
    	$count = count($errormsg);
    	
    	#echo $count."<br>";
    
    	if ($count > 0) {
    		for ($i=0; $i<count($errormsg); $i++) {
    			echo $errormsg[$i]."<br>";
    		}
    		
    	} else {
    		#put your insert into db statement here ( NO ERROR )
    
    			$host="localhost";
    			$dbuser="root";
    			$dbpassword="root";
    
    				mysql_connect($host, $dbuser, $dbpassword) or die ("Unable to Connect to Database");
    				mysql_select_db("secretDB");
    				$query = "INSERT INTO users VALUES ('$username', '$real_name', '$password', '$email')";
    				mysql_query($query);
    			
    
    						$authed = "http://www.php.net";
    						header("Location: $authed");
    			
    						exit;
    
    }
    }
    if ($reset == "Reset"){
    	$username = "";
    	$real_name = "";
    	$password = "";
    	$email = "";
    }						
    						
    						
    ?>
    
    <form name="form1" method="POST" action="<? echo "$PHP_SELF";?>">
    	<table width="34%" border="0" cellspacing="0" cellpadding="0" align="center">
      <tr> 
        <td width="26%">Username :</td>
        <td width="74%"> 
          <input type="text" name="username" value="<? echo("$username");?>">
        </td>
      </tr>
      <tr> 
        <td width="26%">Real name:</td>
        <td width="74%"> 
          <input type="text" name="real_name" value="<? echo("$real_name");?>"
        </td>
      </tr>
      <tr> 
        <td width="26%">Password:</td>
        <td width="74%"> 
          <input type="password" name="password" value="<? echo("$password");?>">
        </td>
      </tr>
      <tr>
        <td width="26%">Email:</td>
        <td width="74%"> 
          <input type="text" name="email" size="30" value="<? echo("$email");?>">
        </td>
      </tr>
    </table>
    <p><center>
    	<input type="submit" name="submit" value="Submit">
    	<input type="reset" name="reset" value="Reset">
    </center></p>
    </form>
    
    
    
    </body>
    </html>
    Now I cannot set my header page (php.net) to load.

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looking at the code the first few lines are pure html code that output to the browser. The problem is that headers are sent with the first output from the server to the browser. Headers can only be sent once. So, as soon as that <html> tag is red the headers are sent, and then much later you try to send a header via php. The php header never makes it because the header for that page already exists.

    Change your code to this and see if it will work:

    Code:
    <? 
    if ($submit == "Submit") {              // If form has been submitted
    	$errormsg = array();
    
    	#$emptyfields = 0;
    	
    	if ($username == "") {
    		$errormsg[] = "Please fill in your username";	
    	}
    	
    	if (!$real_name){
    		$errormsg[] = "Please fill in your Real Name";	
    	}
    	
    	if (!$email) {
    		$errormsg[] = "Please fill in your email address";	
    	}
    	
    	if (!$password) {
    		$errormsg[] = "Please fill in your password";	
    	}
    
    	$count = count($errormsg);
    	
    	#echo $count."<br>";
    
    	if ($count > 0) {
    		for ($i=0; $i<count($errormsg); $i++) {
    			echo $errormsg[$i]."<br>";
    		}
    		
    	} else {
    		#put your insert into db statement here ( NO ERROR )
    
    			$host="localhost";
    			$dbuser="root";
    			$dbpassword="root";
    
    				mysql_connect($host, $dbuser, $dbpassword) or die ("Unable to Connect to Database");
    				mysql_select_db("secretDB");
    				$query = "INSERT INTO users VALUES ('$username', '$real_name', '$password', '$email')";
    				mysql_query($query);
    			
    
    						$authed = "http://www.php.net";
    						header("Location: $authed");
    			
    						exit;
    
    }
    }
    if ($reset == "Reset"){
    	$username = "";
    	$real_name = "";
    	$password = "";
    	$email = "";
    }						
    						
    						
    ?>
    
    <html>
    <body bgcolor=white>
    <center>
    	<font face="verdana" size=1>		
    		<b>Frozened Index Directory Administrator Add</b>
    		<br>
    		This is where current head administrators add new administrators to maintain the Frozened Network
    	</font>
    </center>
    
    <form name="form1" method="POST" action="<? echo "$PHP_SELF";?>">
    	<table width="34%" border="0" cellspacing="0" cellpadding="0" align="center">
      <tr> 
        <td width="26%">Username :</td>
        <td width="74%"> 
          <input type="text" name="username" value="<? echo("$username");?>">
        </td>
      </tr>
      <tr> 
        <td width="26%">Real name:</td>
        <td width="74%"> 
          <input type="text" name="real_name" value="<? echo("$real_name");?>"
        </td>
      </tr>
      <tr> 
        <td width="26%">Password:</td>
        <td width="74%"> 
          <input type="password" name="password" value="<? echo("$password");?>">
        </td>
      </tr>
      <tr>
        <td width="26%">Email:</td>
        <td width="74%"> 
          <input type="text" name="email" size="30" value="<? echo("$email");?>">
        </td>
      </tr>
    </table>
    <p><center>
    	<input type="submit" name="submit" value="Submit">
    	<input type="reset" name="reset" value="Reset">
    </center></p>
    </form>
    
    
    
    </body>
    </html>
    Marty H.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey ! It worked ! Thanks a million !

  11. #11
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, that solved my problem too, thanks a lot.


Bookmarks

Posting Permissions

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