Simple error, overlooking it.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Seifer
Forum Commoner
Posts: 25
Joined: Wed Oct 15, 2003 10:03 pm
Location: Columbia City, IN
Contact:

Simple error, overlooking it.

Post by Seifer »

Here is my code for plogin.php (process login):

Code: Select all

<?php
$dbname = "random";
$dbpass = "random";
$db = "random";
$uname = $_POST['uname'];
$pword = $_POST['pword'];
$link = mysql_connect(localhost, $dbname, $dbpass);
$sdb = mysql_select_db($db, $link);
$result = mysql_query("SELECT uid FROM users WHERE uname = '$uname' AND pword = '$pword'");
if(mysql_num_rows($result) == 1){
	header(Location:"http://seifer.travisbsd.org/");
} else {
	echo "Bad username / password.";
}
?>
When I take out the header it runs fine but I substitute the header for an echo "You are now logged in, $username!". When I put the header in, it makes plogin.php a blank page..Thanks for any future replies.
sinewave
Forum Commoner
Posts: 41
Joined: Tue Sep 10, 2002 4:35 pm
Location: Canada

Post by sinewave »

Code: Select all

<?php
 header(Location:"http://seifer.travisbsd.org/");
?>
Should be

Code: Select all

<?php
 header("Location:http://seifer.travisbsd.org/");
?>
Seifer
Forum Commoner
Posts: 25
Joined: Wed Oct 15, 2003 10:03 pm
Location: Columbia City, IN
Contact:

Post by Seifer »

Still didn't redirect it.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

It's either not reaching that bit of code, or you need the space in ..
header("Location: http://seifer.travisbsd.org");
*note the space between the : http*
Seifer
Forum Commoner
Posts: 25
Joined: Wed Oct 15, 2003 10:03 pm
Location: Columbia City, IN
Contact:

Post by Seifer »

I could have sworn I had this error a year or so ago, and needed to put something at the top of the script.. I forget what though.
Seifer
Forum Commoner
Posts: 25
Joined: Wed Oct 15, 2003 10:03 pm
Location: Columbia City, IN
Contact:

Post by Seifer »

It is ob_start(); that I need to put at top, thanks for the input guys.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, if there's an error somewhere above the header..then it will cause the header to fail as output has already been sent (the error). And if you're error_reporting isn't high enough and/or display_errors is Off then you won't see the error and the header will fail, hence a blank page ;)

So try

Code: Select all

<?php
error_reporting(E_ALL);
...
at the top.
Post Reply