Jump to content


Photo

Can't deal with that 'header'


  • Please log in to reply
5 replies to this topic

#1 devileyes

devileyes
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 30 August 2006 - 11:17 AM

I have a very simple login script everything is working great but when i try to put 'header' in the 'else' conditiont it doesn't work, where is my mistake and how to work it?.Here is my script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>

<body bgcolor="#000000" text="#FF0000" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00">
<div align="center">

<?php

include "connect.php";

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$match = "select id from $table1 where username = '".$_POST['username']."'
and password = '".$_POST['password']."';";

$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);

if ($num_rows <= 0) {
echo "wrong username or password !<br>";
echo "<p>";
echo "<a href=adminlogin.html>Go Back</a>";

} else {
echo "<a href=adminarea.html target=_parent>Enter</a>"; // I wont here to be header ("Location: adminarea.html");
}
?>
</div>
</body>
</html>

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 30 August 2006 - 11:34 AM

You cannot have a header sent after you have outputted anything to the screen, not even a blank!
So you usually put the header() call before all the html stuff.

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#3 devileyes

devileyes
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 30 August 2006 - 11:41 AM

If i  cannot have a header sent after i  have outputted anything to the screen, how the script should look like? What do i have to do? What to change? Pls explain me

#4 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 30 August 2006 - 12:05 PM

Here it is: header before any HTML or other output:
<?php 
include "connect.php";

if (logIn($_POST['username'], $_POST['password']) )
   header("Location: adminarea.html");
else
   die;
   
function logIn($uid, $pwd) {
  // connect to the mysql server
  $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());

  // select the database
  mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());

$match = "select id from $table1 where username = '$uid'
          AND password = '$pwd'"; 

  $qry = mysql_query($match)
    or die ("Could not match data because ". mysql_error());
  $num_rows = mysql_num_rows($qry); 

  if ($num_rows <= 0) { 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<body bgcolor="#000000" text="#FF0000" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00">
<div align="center"> 
<?php	
     echo "<p>wrong username or password !</p>";
     echo "<a href=adminlogin.html>Go Back</a>"; 
	 return false;
  } 
  else
   return true;
}
?>

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 August 2006 - 12:09 PM

Dammit - why is this problem posted twice. PLEASE do NOT post the same thing in different forums - it confuses and wastes people's time.
Legend has it that reading the manual never killed anyone.
My site

#6 devileyes

devileyes
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 30 August 2006 - 01:02 PM


I put it like this but it sas - Could not select database because No Database Selected






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users