/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] header() problems

So I have an admin login page set up where after the admin puts their username and password in and hits the login button it either A. tells them their username or password is incorrect if the username and password doesn’t match the database information or B. redirects them to the index.php page if the username and password are correct. A works its getting B to work is the problem. The code is as follows:

<?php

if (isset($_POST[‘submit’])) {

$username = $_POST[‘username’];
$password = $_POST[‘password’];

$sql = “SELECT * FROM Admin WHERE username = ‘”.$username.”‘ AND password = ‘”.$password.”‘”;
$r = mysql_query($sql);
if (!$r) {
echo ‘<p>Username or Password is incorrect</p>’;
} else {
header(“Location: index.php”);
}
}

?>
<center>

<img src=”assets/LOGO.JPG” width=”244″ height=”61″ alt=”RealtyNET Service Realtors” />

<h3>Administrator Login</h3>

<form method=”post” action=”admin.php” name=”adminLogIn”>
<label>Username:</label>
<input size=”15″ name=”username” type=”text” />
<br />
<br />
<label>Password:</label>
<input size=”15″ name=”password” type=”password” />
<br />
<br />
<input type=”submit” name=”submit” value=”Log In” style=”cursor: pointer;” />
</form>

if i comment out the header() and replace it with a simple echo statement i can see the echo, but when I do the header() function it stays at the admin.php page and empties the text fields.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindDec 17.2008 — try using an absolute url:

header ('Location: http://www.website.com/admin/index.php');

Also, make sure no HTML is output before the header is called.
Copy linkTweet thisAlerts:
@jblackwelderauthorDec 17.2008 — I knew it was going to be one of those 'dur' things that I over looked. I have the php code with the header redirect inside the body:mad:

Thanks alot for your help?
×

Success!

Help @jblackwelder 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...