why "header" does not work in my code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarah89
    New Member
    • Feb 2012
    • 5

    why "header" does not work in my code?

    hello ^^


    i used header in my codes, and it was working fine in the local server. but when i upload it to the public server i keep get the following error:

    Warning: Cannot modify header information - headers already sent by (output started at /home/movc/public_html/dbconnector.php :23) in /home/movc/public_html/loginaction.php on line 31


    in dbconnector.php :
    i connect to the server and i never used header there!

    and in loginaction.php i used:
    [CODE] include_once("d bconnector.php" ); [/DODE]

    and this is the part of my code that i used header in:
    Code:
     
    	//Check whether the query was successful or not
    	if($result) {
    		header('location: welcome_msg1.php');
    exit();}
    	else
    	header('location: erorr_msg1.php');
    exit();

    can you please tell me where i did wrong?
    thanks so much ^^
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    it’s like the error messages says, 8 lines before you set the header, you have output, which causes the response body to begin and which renders any more headers invalid.

    Comment

    • sarah89
      New Member
      • Feb 2012
      • 5

      #3
      thank you so much ^^ :*

      but, what kind of error?
      i review the code many times and couldn't find it!

      if you can help me more and see the code:
      Code:
      //Create query
      	
      	$qry="SELECT * FROM user WHERE username='"$un"' AND pw='"$pw"';";
      	$result=mysql_query($qry);
      	
      	//Check whether the query was successful or not
      	if($result) {
      	if(mysql_num_rows($result) == 1) {
      			//Login Successful
      
      	        $member = mysql_fetch_assoc($result);
      			$_SESSION['uid'] = $member['u_id'];
      			
      			header("location: controlpanel.php");
      			
      			exit();
      		}else {
      			//Login failed
      			header("location: index.php");
      			
      			exit();
      		}
      	}else {
      		die("Query failed");
      	}

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        that kind of error:
        Warning: Cannot modify header information - headers already sent by (output started at /home/movc/public_htm/dbconnector.php :23) in /home/movc/public_html/loginaction.php on line 31

        Comment

        • sarah89
          New Member
          • Feb 2012
          • 5

          #5
          ^^
          i mean the error in the code!
          what i should change in my code to make this error msg stop!!

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            remove the output before the header() call.

            Comment

            Working...