Jump to content

Users Level Login System Leads to Blank Page


lybat

Recommended Posts

I'm creating a users level login system in php & mysql. However, it leads to a white blank page. I can't figure the error. Any help is much appreciated. Thanks.

 

Form.html

 

 

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>MIS Electronic Request</title>
  <link rel="stylesheet" href="css/style.css">
 
</head>
<body>
  <br>
 
  <form method="post" action="main.php" class="login">
    <p>
      <label for="login">Username:</label>
      <input type="text" name="myusername" id="myusername" value="Employee id">
    </p>

    <p>
      <label for="password">Password:</label>
      <input type="password" name="mypassword" id="mypassword" value="4815162342">
    </p>

    <p class="login-submit">
      <button type="submit" class="login-button">Login</button>
    </p>

  </form>

</body>
</html>
 

 

Main.php

 

 

<?php
session_start();
$host="localhost";
$username="root";
$password="******";
$db_name="htdocs";
$tbl_name="users";

mysql_connect("$host", "$username", "$password")or die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db("$db_name")or die("Unable to select database: " . mysql_error());

if (isset($_POST['submit']))
{
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);


if($count==1){
   if (user_level == 1) {
        $_SESSION['myusername'] = $myusername;
        $_SESSION['mypassword'] = $mypassword;
        header("Location:Admin_home.php");
        }
   else if (user_level == 2) {
        $_SESSION['myusername'] = $myusername;
        $_SESSION['mypassword'] = $mypassword;
        header("Location:home.php");
   }
}
else {
echo "Wrong Username or Password";
}
}

?>

 

Link to comment
Share on other sites

Thanks for the reply. The blank page issue has been resolved. But this time i got this error:

 

Error:

 

Notice: Use of undefined constant user_level - assumed 'user_level' in C:\wamp\www\htdocs\main.php on line 34

Notice: Use of undefined constant user_level - assumed 'user_level' in C:\wamp\www\htdocs\main.php on line 39

Link to comment
Share on other sites

Hi i already did that. still error..

 

 

if($count==1){
   if ($user_level == 1) {
        $_SESSION['myusername'] = $myusername;
        $_SESSION['mypassword'] = $mypassword;
        header("Location:Admin_home.php");
        }
   else if ($user_level == 2) {
        $_SESSION['myusername'] = $myusername;
        $_SESSION['mypassword'] = $mypassword;
        header("Location:home.php");
   }
}

Link to comment
Share on other sites

and you still should have a space after Location:

header("Location:Admin_home.php");
 header("Location:home.php");

but you don't need the space in else if you can use elseif

 

You don't need the space after "Location:", if you had tried it, you would see it works without the space.

Link to comment
Share on other sites

You don't need the space after "Location:", if you had tried it, you would see it works without the space.

You are right. The space is is ignored and multiple spaces after the colon should work too (according to the RFC). I thought I had an issue a few moths ago that I solved by adding a space after the colon in a header, but I must be remembering it incorrectly. I stand corrected. Sorry.

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.