Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6335795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:55:33+00:00 2026-05-24T18:55:33+00:00

I am having problems getting my page to redirect using the header method. I

  • 0

I am having problems getting my page to redirect using the header method. I think I know what the problem is. But I am very new to the PHP scene so I don’t know what else to try. From what I have read the header() method will not fire if a page has already sent data prior to the header. I feel this could be part of my problem because I have several echo statements before my header function. Could it be something else? How do I get around this?

An echo statement proves that the correct username and password are being located. I put a test echo statement where the header is, and it works just fine. So, I know the database is finding the correct information. The page refreshes when the info is inserted. Thanks for looking.

<div id= "sidebar" >
    <div id="login-box">    
        <form name="client-login" action="<?php $_SERVER['PHP_SELF']; ?>"  method="post">
            <label id="user-lbl">Username:</label><br /><input type="text"
                name="username" id="username" /><br /> <label id="pass-lbl">Password:</label><br /><input
                type="password" name="password" id="password" /><br />     <label>&nbsp;</label><input
                type="submit" value="Login" class="submit" id="login" />
        </form>     
<?php 
$username = $_POST['username'];
$password = $_POST['password'];

if((!isset($username)) || (!isset($password))){

    echo "<p>Username is $username. Password is $password.</p>";

     }else{

    $mysql = mysql_connect("myhost", "username", "password");
    if(!$mysql){
    echo "<p>Cannot connect to database!</p>";}
    $selected = mysql_select_db("mydb", $mysql);
    if(!$selected){
    echo "<p>Cannot find database!</p>";}

    $query = sprintf("SELECT count(*) FROM users WHERE username = '%s' AND password = '%s'", mysql_real_escape_string($username),mysql_real_escape_string($password));

    $result = mysql_query($query, $mysql );
    if(!$result){
    echo "<p>Cannot run query.</p>";}

    $row  = mysql_fetch_row($result);
    $count = $row[0];
    if ($count > 0){
    header("Location: account.php"); die();} else {echo "<p>Invalid username or password!</p>";}
}  
?>

    </div><!-- #login-box -->

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:55:33+00:00Added an answer on May 24, 2026 at 6:55 pm

    If you call header(), then it should be called BEFORE any other function that prints an output to the HTML stream, OR before any HTML statements in that file. You cannot send even a newline character before the header() call.

    Here in your case, first you are sending the <div id= "sidebar" > and other 7 lines to the client, and then only you are calling the header() function. That’s why the error happened to you.

    Reason:

    The header() call is meant to deliver the HTTP header information to the client browser. The header information should be the first information to be sent to the client. If you are not calling the header() in your PHP script, the PHP will automatically send a header information just before sending the very first line of your PHP file.

    Once a header is sent, you cannot send another header in the same PHP file. So, if you want to send a header exclusively, send it before any other body content starts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem getting a simple ASP.NET webpage to display. The page contains
I am having problems getting my form to Post to my Save method in
I am having problems getting validation to work for a form built using Zend_Form.
I'm having problems getting AppendHeader to work properly if I am also using an
I'm having problems getting the new data from the RandomNumbers List I got this
The page having problems is... http://schnell.dreamhosters.com/index.php?page=gallery# I use Firebug to debug my jQuery and
I am using HTML Purifier in my PHP project and am having trouble getting
In my application, I am having problems getting a stylesheet because it is using
Having some problems with getting some ajax script to work. Using this as the
I am having problems with getting a HTML editor working. We are using contentEditable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.