I hv make a html file on which I placed 2 fields username and passowrd.I also included a php file named "check.php"

The code in the check.php is as follows:

<body>
<?
$con = mysql_connect("localhost","","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("alauddin", $con);
$name=$_POST['txtusername'];
$password=$_POST['txtpw'];
$result = mysql_query("SELECT username,pw FROM login");
while($row = mysql_fetch_array($result))
  {
 if($name==$row['username'] && $password==$row['pw']){
  $valid_user = 1;
  break;
  }
 else
 $valid_user = 0;
  }
  
 if($valid_user==1){
header("Location: http://www.google.com");
}
 else
 header("Location: http://www.yahoo.com");
mysql_close($con);
?>
</body>

Plz Reply soon.

Hi.

I don't understand what's the problem.

Hint : Why don't you do the check in the query :

$result = mysql_query("SELECT username,pw FROM login WHERE username='$name' AND pw='$password' ");

if($result!='NULL')
	{
	header("Location: http://www.google.com");
	}
	
else {
            header("Location: http://www.yahoo.com");
            }

Hint 2:

$con = mysql_connect("localhost","","") or die('Could not connect: ' . mysql_error());

- Mitko Kostov

thankx for ur guidance.

I m receiving an error.."Cannot modify header information".I need to open a page whn the user loginned in,bt its giving the header error.

Kindly give me solution.

Headers must be sent before any output.
So you cannot use it after/in any HTML, for example in <body>.

<BODY ...> is the section that holds everything that is actually displayed. All the text, headers, tables, etc are in the <BODY ...> section.

You don't need <body> in the code above, because you don't display anything.


- Mitko Kostov

Headers must be sent before any output.
So you cannot use it after/in any HTML, for example in <body>.

You don't need <body> in the code above, because you don't display anything.


- Mitko Kostov

Bt i m receiveing the same error..after removing the body tag...??

You have to remove any blank spaces before the php code.

The problem is that many editors seem to add additional blanks (spaces) and/or empty lines at the end of a file when you edit it. This so-called whitespace is then sent to the browser when the file is loaded and interferes with the header of a page that tries to send to the browser, often causing problems such as login problems.

If you are using UTF-8, disable BOM.


- Mitko Kostov

I m using dreamweaver..n it is still giving the same problems.?

The header problem is just solved,n the following code is of php file:

<?
$con = mysql_connect("localhost","","");
if (!$con){
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("alauddin", $con);
$name=$_POST['txtusername'];
$password=$_POST['txtpw'];
$result = mysql_query("SELECT username,pw FROM login WHERE username='$name' AND pw='$password' ");
while($row = mysql_fetch_array($result))
  {
 if($result!='NULL')
	{
	header("Location: http://www.google.com");
	}
else {
            header("Location: http://www.yahoo.com");
            }
}
mysql_close($con);
?>

Now the problem is that Its opening the google page if the user is authenticated bt its showing just a blank page whn the user is invalid.
I tried to print a msg by "Echo" whn the user is invalid bt its just showing the blank page.

Kindly guide.

Regards,

try an else if statement:

while($row = mysql_fetch_array($result))
{
if($result!='NULL')
{
header("Location: http://www.google.com");
}
elseif ($result='NULL'){
header("Location: http://www.yahoo.com");
}
}

hope this helps........

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.