0

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.

3
Contributors
8
Replies
9
Views
9 Years
Discussion Span
Last Post by ryan_vietnow
0

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

0

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.

0

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

0

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...??

0

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

0

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,

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.