0

I'm making a PHP MySQL page for a school project, and I am trying to make an admin area that you need to login to access. Problem is, when I login with the correct username and password, it sends me to a blank page. Same happens if I type the wrong username or password. I'm using header to redirect to the ADM_hovedside.php. It's not exactly my code, but I have changed it to fit my database. I've also confirmed that it works when i remove the header and replace it with an echo command, similar to the one just below the header command. I'm just really stuck and no forum posts has solved the issue for me. Would appreciate any help that may lead to an answer. Thanks. Here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<?php 
define('DB_HOST', 'localhost:8888'); 
define('DB_NAME', 'berntbilpleie'); 
define('DB_USER','root'); 
define('DB_PASSWORD','root'); 
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error()); 
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());
function SignIn()
{ 
session_start(); //starting the session for user profile page 
if(!empty($_POST['user'])) //checking the 'user' name which is from Sign-In.html, is it empty or have some text 
{
 $query = mysql_query("SELECT * FROM brukernavn where brukernavn = '$_POST[user]' AND passord = '$_POST[pass]'") or die(mysql_error());
 $row = mysql_fetch_array($query) or die(mysql_error());
 if(!empty($row['brukernavn']) AND !empty($row['passord'])) 
 {
      $_SESSION['brukernavn'] = $row['passord']; 
      header("Location: ADM_hovedside.php" );
      }
      else 
      { 
      echo("FEIL BRUKERNAVN OG/ELLER PASSORD!") ;
      }
}
} 
if(isset($_POST['submit'])) 
{ 
SignIn(); 
}
?> 
</body>
</html>

I also have this code on the ADM_hovedside.php site:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
session_start();
if(!isset($_SESSION['user'])){
header("Location: index.php");

}
?>
<p>
This is a test page
</p>
</body>
</html>
  • Also, you can't redirect after outputting HTML – John Conde Mar 21 '17 at 17:29
  • "500 Internal Server Error" (or a blank page) means your script is throwing an error but PHP is configured to hide it from you. You need to fix it ASAP because coding without the aid of error messages is hard. As quick start, you can set the `error_reporting` and `display_errors` directives in your computer's system-wide `php.ini` file ([details here](http://stackoverflow.com/a/5680885/13508)). Errors thumb rule: show in development, log in production. – Álvaro González Mar 21 '17 at 17:38

0 Answers0