Jump to content

Can't deal with that 'header'


devileyes

Recommended Posts

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>"; [color=red]// I wont here to be header ("Location: adminarea.html");[/color]
}
?>
</div>
</body>
</html>
Link to comment
Share on other sites

Here it is: header before any HTML or other output:
[code]<?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;
}
?>[/code]

Ronald  8)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.