PHP Login Redirect Problem

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
jevic
Forum Newbie
Posts: 2
Joined: Tue Nov 16, 2010 1:54 pm

PHP Login Redirect Problem

Post by jevic »

Hi

I am having a problem with my php login code Each time I log in I am being redirected back to the login. Could you please look at my code and see what I am doing wrong.

Thankyou

<?php
session_start();
mysql_connect("localhost", "c3254640","c3254640")or die("cannot connect");
mysql_select_db("c3254640")or die("cannot select DB");
$Username=$_POST['Username'];
$Password=$_POST['Password'];
$query = "SELECT * FROM User WHERE Username= '$Username' AND Password='$Password'";
$result = mysql_query ($query);
if (mysql_num_rows($result) > 1)
{
$_SESSION["authenticatedUser"] = $Username;
header("Location: logonpage.php");
}
else
{
$_SESSION["message"] = "Could not connect as $Username " ;
header("Location: login.php");
}
?>
WorldCom
Forum Commoner
Posts: 45
Joined: Sat Jun 24, 2006 8:14 am
Location: Ontario, Canada

Re: PHP Login Redirect Problem

Post by WorldCom »

Try

Code: Select all

if (mysql_num_rows($result) >= 1)
jevic
Forum Newbie
Posts: 2
Joined: Tue Nov 16, 2010 1:54 pm

Re: PHP Login Redirect Problem

Post by jevic »

WorldCom wrote:Try

Code: Select all

if (mysql_num_rows($result) >= 1)
thankyou for the reply but that still doesnt fix it
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Login Redirect Problem

Post by Celauran »

Have you also checked the code in logonpage.php? Could it be redirecting you back to login.php?
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: PHP Login Redirect Problem

Post by thinsoldier »

Did you accidentally set your login form tag to GET instead of post?
Warning: I have no idea what I'm talking about.
Post Reply