Jump to content

Header Error (yes I have read the sticky)


Nodral

Recommended Posts

Hi All

 

I'm getting a header error on the code given and having read the sticky on this forum cannot find where the error is and why my page won't redirect.

 

Any ideas?

 

connect.php

<?php
$link = mysql_connect('localhost', '****', '********');
if (!$link)
{
echo'1Unable to connect to the database server.';

exit();
}

if (!mysql_set_charset('utf8', $link))
{
echo'2Unable to connect to the database server.';

exit();
}

if(!mysql_select_db('******', $link))
{
echo'3Unable to connect to the database server.';

exit();
}

?>

 

index.php

<?php
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');

//set variables from login form below
if(strlen($_POST['username'])>1){
$username=$_POST['username'];
}

if(strlen($_POST['password'])>1){
$password=$_POST['password'];
}

$register=$_POST['register'];
$forgotten=$_POST['forgotten'];


//log the user in or create an acct for learning styles
include_once("connect.php");
?>
<form method="POST" action="">
<p>Username <input type="text" name="username" size="40"></p>
<p>Password <input type="password" name="password" size="40"></p>
<p><input type="submit" value="Login">
<p>If you have not previously completed this questionnaire, please click the 'Register' button below, alternatively if you have forgotten your login details please click the 'Forgotten Login' button.</p>
<p><input type="submit" name="register" value="Register">   <input type="submit" name="forgotten" value="Forgotten Login"></p>
</form>
<?php

if(isset($username, $password)){
//log user in
//include("login.php");


}

elseif(isset($register)){
//divert to reg form
$extra = 'register.php';
header("Location: http://$host$uri/$extra");

}

elseif(isset($forgotten)){
//ask for email address and send mail of details
//include("forgotten");
}

elseif((isset($username) and !isset($password)) or (!isset($username) and isset($password))){
//give message of details req
echo "no details";
}
?>

 

Error  -Warning: Cannot modify header information - headers already sent by (output started at D:\Documents\AI24\Web\skooch\learning_styles\index.php:26) in D:\Documents\AI24\Web\skooch\learning_styles\index.php on line 40

 

Any ideas anyone?

 

Link to comment
Share on other sites

Like the sticky says, you can't have any output sent to the browser before attempting to send a header.  Your form is output.  You need to redesign your page.  As a hint, well-formed PHP pages do all of their processing first, then show output.

Link to comment
Share on other sites

nightslyr is right, for an informative post, there are a few other things that can cause this error.

 

1. white space outside of the php start and end tags.

 

2. extra characters outside of the php start and end tags.

 

3. try changing output_buffering=on in php.ini

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.