/    Sign up×
Community /Pin to ProfileBookmark

header redirecton problem

i am using the following code and i keep getting

<?
session_start();
include(“dbblsr.php”);

mysql_select_db(“cgowie_teamcanada”, $conn);

$result = mysql_query(“SELECT * FROM teamcanada WHERE reqemail=’$_POST[reqemail]'”);
$row = mysql_fetch_array($result);
$pass = $row[‘password’];
$rights = $row[‘useright’];
$name = $row[‘reqfirst’];
$email =$row[‘reqemail’];

IF ($pass != md5($_POST[‘password’])){
(“Incorrect password.”);
header( ‘Location: loginca.php’ ) ;
}
ELSE{
$_
SESSION[‘access’]= $_SESSION[‘access’]+1;
$_
SESSION[‘rights’]= $rights;
$_SESSION[‘reqfirst’]= $name;
$_
SESSION[‘reqemail’]= $email;
header( ‘Location: team_canada.php’ ) ;

}
?>
keep getting an error saying something along the lines of:

Warning: Cannot add header information – headers already sent by (output started at

etc. etc. etc.

Could somebody please tell me what I need to do differently?

to post a comment
PHP

29 Comments(s)

Copy linkTweet thisAlerts:
@scragarFeb 27.2008 — that error means that you have content before your headers/sessions, possibly a space or something before quotes or some such...

and read my sig:
Copy linkTweet thisAlerts:
@civeyauthorFeb 28.2008 — I use the same code on a different page with a headers and it worked fine the only thing i change was the db and the headers
Copy linkTweet thisAlerts:
@civeyauthorFeb 28.2008 — I use the same code and just change the table that i check and it works fine. I am new to this can some help. Do i need to have the password and userid located at a certain poition in the sql table?
Copy linkTweet thisAlerts:
@TheRaveFeb 28.2008 — Its nothing to do with the password and userid in the table.

The error is related to these lines:
[code=php]header( 'Location: loginca.php' ) ;
//snip
header( 'Location: team_canada.php' ) ;[/code]


There must NOT be any kind of output before these lines. There must be NO content (including whitespace) outside of your PHP tags before these lines.

Try attaching your code files as well as the whole error. It might make it easier for us.
Copy linkTweet thisAlerts:
@MrCoderFeb 28.2008 — Add this at the very top of your code..
[code=php]
ob_start();
[/code]
Copy linkTweet thisAlerts:
@civeyauthorFeb 28.2008 — Thanks it worked. Can you tell me what that line of code does
Copy linkTweet thisAlerts:
@TheRaveFeb 28.2008 — Normally php outputs during processing, so the starts receiving the page while the script is still running.

The ob functions control buffering of output. With ob started php outputs everything to a buffer. Only when the php has finished processing (or if the buffer is explicitly flushed) does the user start receiving the page.

The added code means that your header calls (which aren't buffered) are being sent to the client before they receive any output.
Copy linkTweet thisAlerts:
@civeyauthorFeb 28.2008 — With that code it does go to header location but it does not check the db and it does not execute the else statement?
Copy linkTweet thisAlerts:
@TheRaveFeb 28.2008 — With the ob started it will still execute all the code.
Copy linkTweet thisAlerts:
@civeyauthorFeb 28.2008 — That is not happening for me
Copy linkTweet thisAlerts:
@civeyauthorFeb 28.2008 — This is what the code looks like now when i execute it displays the header for the incorret password but when i input a user email and password it redisplays the same thing.

<?

ob_start();

session_start();

include("dbblsr.php");

mysql_select_db("cgowie_teamcanada", $conn);

$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");

$row = mysql_fetch_array($result);

$pass = $row['password'];

$rights = $row['useright'];

$name = $row['reqfirst'];

$email =$row['reqemail'];

IF ($pass != md5($_POST['password'])){

("Incorrect password.");

header( 'Location: loginca.php' ) ;

}

ELSE{

$_
SESSION['access']= $_SESSION['access']+1;

$_
SESSION['rights']= $rights;

$_SESSION['reqfirst']= $name;

$_
SESSION['reqemail']= $email;

header( 'Location: team_canada.php' ) ;

}

?>

Then i try this notice that it has a different db and this db does not include the table i am trying to check but it still got to the incorrect header location

<?

ob_start();

session_start();

include("[COLOR="red"]db.php[/COLOR]");

mysql_select_db("cgowie_teamcanada", $conn);

$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");

$row = mysql_fetch_array($result);

$pass = $row['password'];

$rights = $row['useright'];

$name = $row['reqfirst'];

$email =$row['reqemail'];

IF ($pass != md5($_POST['password'])){

("Incorrect password.");

header( 'Location: loginca.php' ) ;

}

ELSE{

$_
SESSION['access']= $_SESSION['access']+1;

$_
SESSION['rights']= $rights;

$_SESSION['reqfirst']= $name;

$_
SESSION['reqemail']= $email;

header( 'Location: team_canada.php' ) ;

}

?>
Copy linkTweet thisAlerts:
@civeyauthorFeb 28.2008 — any ideas
Copy linkTweet thisAlerts:
@scragarFeb 28.2008 — you still havn't used the forums [noparse][code=php] and [/code][/noparse] tags around your code, which means that it's far harder to spot errors, so I'm gonna wait for that, like I waited for you to do it earlier with your first post.

http://www.webdeveloper.com/forum/showpost.php?p=546768&postcount=5 <-- read!
Copy linkTweet thisAlerts:
@civeyauthorFeb 28.2008 — This is all php code

<?php

ob_start();

session_start();

include("dbblsr.php");

mysql_select_db("cgowie_teamcanada", $conn);

$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");

$row = mysql_fetch_array($result);

$pass = $row['password'];

$rights = $row['useright'];

$name = $row['reqfirst'];

$email =$row['reqemail'];

IF ($pass != md5($_POST['password'])){

("Incorrect password.");

header( 'Location: loginca.php' ) ;

}

ELSE{

$_
SESSION['access']= $_SESSION['access']+1;

$_
SESSION['rights']= $rights;

$_SESSION['reqfirst']= $name;

$_
SESSION['reqemail']= $email;

header( 'Location: team_canada.php' ) ;

}

?>
Copy linkTweet thisAlerts:
@civeyauthorFeb 28.2008 — [code=php]<?php
ob_start();
session_start();
include("dbblsr.php");

mysql_select_db("cgowie_teamcanada", $conn);

$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
$row = mysql_fetch_array($result);
$pass = $row['password'];
$rights = $row['useright'];
$name = $row['reqfirst'];
$email =$row['reqemail'];

IF ($pass != md5($_POST['password'])){
("Incorrect password.");
header( 'Location: loginca.php' ) ;
}
ELSE{
$_SESSION['access']= $_SESSION['access']+1;
$_SESSION['rights']= $rights;
$_SESSION['reqfirst']= $name;
$_SESSION['reqemail']= $email;
header( 'Location: team_canada.php' ) ;

}
?>
[/code]
Copy linkTweet thisAlerts:
@scragarFeb 28.2008 — sorry for that, but I'm busy atm, and I did say so far earlier and it's mentioned in the thread marked [b]FAQ - Please Read Before Posting![/b] at the top of the PHP forum.


I'm going to assume that [b]dbblsr.php[/b] contains your connection, and that that's not the problem, which means you have one of 3 possible causes:
[code=php]"reqemail='$_POST[reqemail]'"[/code]is evaluating as [code=php]"reqemail='Array[reqemail]'"[/code]since $_POSt is an array, in which case the solution is[code=php]"reqemail='{$_POST[reqemail]}'"[/code]the braces tell PHP where the variable starts and ends.
[code=php]$row = mysql_fetch_array($result);[/code]since your returning 0 results this means that attempting to fetch the array causes an error. Something I doubt would be the problem, but it might be worth considering something more like:
[code=php]if(mysql_num_rows($result)
$row = mysql_fetch_array($result);
else
$row = array();[/code]
since this will avoid errors, although it's not the best error catching it is the simplest.

[code=php]$_SESSION['access']= $_SESSION['access']+1;[/code]$_SESSION['access'] is unset, although I don't have much experience with this myself I can say that it's best to be sure at all times:[code=php]if(isset($_SESSION['access']))
$_SESSION['access']++;
else
$_SESSION['access']=1;[/code]
Copy linkTweet thisAlerts:
@civeyauthorFeb 29.2008 — as i stated i am new to php i try using this code as you suggested and it seems there is something missing on the first line

[code=php]if(mysql_num_rows($result)
$row = mysql_fetch_array($result);
else
$row = array();[/code]
?
Copy linkTweet thisAlerts:
@scragarFeb 29.2008 — oops, closing bracket
[code=php]if(mysql_num_rows($result) ) // <-- right here
$row = mysql_fetch_array($result);
else
$row = array();[/code]
Copy linkTweet thisAlerts:
@civeyauthorFeb 29.2008 — yep i caught it just after i post

I add the [code=php]ob_start();[/code] to the code and it seems like it is working but as far as i can tell the db is not checked and i dont get to ths portion [code=php]ELSE{
if(isset($_SESSION['access']))
$_SESSION['access']++;
else
$_SESSION['access']=1;
$_SESSION['rights']= $rights;
$_SESSION['reqfirst']= $name;
$_SESSION['reqemail']= $email;
header( 'Location: team_canada.php');

}
?>[/code]
of the code.
Copy linkTweet thisAlerts:
@scragarFeb 29.2008 — only thing I can think of now is the lesser things like form's and such, for a test try:

[code=php]<?php
ob_start();
session_start();
include("dbblsr.php");

mysql_select_db("cgowie_teamcanada", $conn);

$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='{$_POST[reqemail]}'");
if(mysql_num_rows($result))
$row = mysql_fetch_array($result);
else
$row = array();

print_r($_POST);// show all $_POST values
echo "nn<p>".md5($_POST['password'])."</p>nn";// show MD5 password for comparison with DB
print_r($row);// show DB info

exit;

...
[/code]
then check the names of the variables and such against what your using, if $row is empty then your just not getting any results from the DB. I occasionaly do debuging like this if I can't find a problem, the idea is to list everything that it could possibly be related to, and see if you can spot anything out of the ordinary.
Copy linkTweet thisAlerts:
@civeyauthorFeb 29.2008 — I think that could be the problem here is my output

Array ( )

d41d8cd98f00b204e9800998ecf8427e

Array ( ) ?
Copy linkTweet thisAlerts:
@scragarFeb 29.2008 — $_POST is empty?

check your form.
[code=html]<form method='post' action='wherever'>[/code]
Copy linkTweet thisAlerts:
@civeyauthorFeb 29.2008 — I think it ok? [code=html]<form method="post" action="checkca.php">[/code]
Copy linkTweet thisAlerts:
@civeyauthorFeb 29.2008 — $_POST is empty because i did not enter anything. However when i make an entry this is what the output looks like :

Array ( [emailadd] => testign [password] => [Submit] => Login )

d41d8cd98f00b204e9800998ecf8427e

Array ( )

What is happening is the field that should hold the email has the incorrect var. it should be [COLOR="Red"]reqemail not emailadd[/COLOR] can you help?
Copy linkTweet thisAlerts:
@scragarFeb 29.2008 — just rename the input box.
Copy linkTweet thisAlerts:
@civeyauthorFeb 29.2008 — I did that and the result is the same ?
Copy linkTweet thisAlerts:
@civeyauthorFeb 29.2008 — I did rename the input box that didn't help. Thinking i need to some how reset the result array i tried this
[code=php]<?php
ob_start();
session_start();
include("dbblsr.php");
$row = array();
mysql_select_db("cgowie_teamcanada", $conn);

$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
if(mysql_num_rows($result))
$row = mysql_fetch_array($result);
else
$row = array();
print_r($_POST);// show all $_POST values
echo "nn<p>".md5($_POST['password'])."</p>nn";// show MD5 password for comparison with DB
print_r($row);// show DB info

exit;[/code]


that gave me the correct var for email which is reqemail, but when I try to input a user from the db it gives me duplicate. As I stated I am new at this can you help
Copy linkTweet thisAlerts:
@civeyauthorFeb 29.2008 — I did some checking and as i state in the previous post i an reading the db with the following code
[code=php]<?php
ob_start();
session_start();
include("dbblsr.php");

mysql_select_db("cgowie_teamcanada", $conn);

$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
if(mysql_num_rows($result))
$row = mysql_fetch_array($result);
else
$row = array();

$pass = $row['password'];
$rights = $row['useright'];
$name = $row['reqfirst'];
$email =$row['reqemail'];

IF ($pass != md5($_POST['password'])){
("Incorrect password.");
header('Location: loginca.htm');
}
ELSE{
if(isset($_SESSION['access']))
$_SESSION['access']++;
else
$_SESSION['access']=1;
$_SESSION['rights']= $rights;
$_SESSION['reqfirst']= $name;
$_SESSION['reqemail']= $email;
header( 'Location: team_canada.php');

}
?>[/code]
but when i imput the user name and pass I am getting dup

could this possible be my html code
[code=html]<form method="post" action="checkca.php">
<div align="center">
<table border="0" width="77%" id="table1" style="border-collapse: collapse">
<tr>
<td width="146"><font face="Arial" size="2"></font></td>
<td width="8">&nbsp;</td>
<td>Incorrect Email or Password try again</td>
</tr>
<tr>
<td width="146">
<p align="right"><font size="2" face="Arial">Email</font></td>
<td width="8">&nbsp;</td>
<td><font face="Arial"><input type="text" name="reqemail" size="27"></font></td>
</tr>
<tr>
<td width="146">
<p align="right"><font size="2" face="Arial">Password</font></td>
<td width="8">&nbsp;</td>
<td><font face="Arial"><input type="password" name="password" size="27"></font></td>
</tr>
<tr>
<td width="146">
<font face="Arial">
<input type="submit" value="Login" name="B1" style="float: right"></font></td>
<td width="8">&nbsp;</td>
<td><font face="Arial"><input type="reset" value="Reset" name="B2"></font></td>
</tr>
</table>
</div>
</form>[/code]

?
Copy linkTweet thisAlerts:
@civeyauthorMar 01.2008 — Thanks every one!! I got it ?
×

Success!

Help @civey spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...