hii

i am trying to write code for Login but its not working.. i have used this code for my another loginpage there its working dont knw y its not on working on my new page.

when ever i click on Login button it goes in else statement that open sorry page.

heres code i am using..

<?php
if(isset($_REQUEST['Login']))
{
$Username=$_REQUEST['username'];
$Password=$_REQUEST['password'];

$query="SELECT * FROM user";
$result=mysql_query($query);
		while($nt=mysql_fetch_array($result))
		{
		  if(($nt['name']==$Username)&&($nt['password']==$Password))
		  {
		 
		 header("Location:buyticket.php");
		  break;
		  } 
		  else
		 
		 {
		  header("Location: sorry.php");
		  break;
		}
	}
}

i have al the names and variables and matched from my database they are correct.

can anyone tell why it is going in else condition even when i am giving correct username and password

Recommended Answers

All 2 Replies

Because the first record inspected in the loop is not the one you're expecting, so it goes to the else.
To verify, delete all users but one (need I mention to take a backup first) and test again.
This is most definately not the best way to accomplish what you're trying to do.

problem is solved. i was writing this code outside form tags.
:-D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.