Hello,

I am trying to create a login box that processs the form to another file after login:

index.php

<form action="login.php" method="POST">
<input type="text" class="form" name="username"><br>
<input type="password" class="form2" name="password"></div>
<input type="submit" class="login" name="submit" value=""></input></div>
<div style="margin: -235px 0 0 850px;"><a href="create_account.php">Create an Account</a><br><a href="forget_password.php">Forgot Password</a></div>
<div style="margin: 20px 0 0 630px;"><input type="checkbox" name="keeplogin" value="Keep me logged in">Keep me logged in<br></div>
</form>

login.php

<?php

ob_start();
session_start();

?>

<!DOCTYPE HTML>

<html>
<head>
<!-- alert add -->
<link id="ui-theme" rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.0/themes/ui-lightness/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="http://pontikis.github.com/jui_alert/v2.0.0/jquery.jui_alert.css"/>
<!-- custom classes -->
<link rel="stylesheet" href="index.css">

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.0/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://pontikis.github.com/jui_alert/v2.0.0/jquery.jui_alert.min.js"></script>
<script type="text/javascript" src="http://pontikis.github.com/jui_alert/v2.0.0/i18n/en.js"></script>
<script type="text/javascript" src="index.js"></script>
<!-- end -->


<link href= "../css/admin.css" rel="stylesheet" type="text/css" media="screen">

<script type="text/javascript">

$(function() {
 /*
  $("#user_message1").jui_alert({
    containerClass: "container1 ui-widget",
    message: "<img src='images/megaphone.png' style='float: left; width: 30px; margin-right: 10px;'>This is a sample message. It will disappear after 6 sec (except you press the pin button)",
    timeout: 6000,
    messageIconClass: ""
  });

  $("#user_message2").jui_alert({
    containerClass: "container2 ui-widget",
    message: "This is a sample message. It will not disappear automatically. More information <a href='http://www.google.com' target='_blank'>here</a>.",
    messageBodyClass: "message2",
    timeout: 0,
    use_effect: {effect_name: "slide", effect_options: {"direction": "left"}, effect_duration: "500"}
  });
*/ 
  $("#user_message3").jui_alert({
    containerClass: "container3 ui-widget",
    message: "The login is invalid",
    timeout: 0,
    messageAreaClass: "jui_alert_message_area ui-state-error ui-corner-all",
    messageIconClass: "jui_alert_icon ui-icon ui-icon-alert"
  });

});
</script>

<style>
.container1 {
  width: 40%;
  margin: 20px;
}

.container2 {
  width: 50%;
  margin: 20px;
}

.container3 {
  width: 40%;
  margin: 20px;
}

.message2 {
  font-size: 13px;
  font-family: Arial, sans-serif;
  letter-spacing: 1px;
}

</style>
</head>

<?php

include('includes/koneksi.php');

$error = "";

echo "first";

if (@$_POST['submit']) { 

/* the files */
echo "It works!";

// username and password sent from form
$username=$_POST['username'];
$password=$_POST['password'];

// To protect MySQL injection (more detail about MySQL injection)

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$encrypted_password = md5($password);

$sql = "SELECT * FROM student WHERE stu_username='$username' and stu_password='$encrypted_password' and access_level_id='3'" or die(mysql_query);
$result=mysql_query($sql);

$sql2 = "SELECT * FROM teacher WHERE teach_username='$username' and teach_password='$encrypted_password'" or die(mysql_query);
$result2=mysql_query($sql2);

$sql3 = "SELECT * FROM user WHERE username='$username' and password='$encrypted_password'" or die(mysql_query);
$result3=mysql_query($sql3);

$sql4 = "SELECT * FROM student WHERE stu_username='$username' and stu_password='$encrypted_password' and access_level_id='4'" or die(mysql_query);
$result4=mysql_query($sql4);


// Mysql_num_row is counting table row
$stu_count=mysql_num_rows($result);
$teach_count=mysql_num_rows($result2);
$admin_count=mysql_num_rows($result3);
$stuM_count=mysql_num_rows($result4);

// If result matched $username and $password, table row must be 1 row

if ($stu_count>=1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
//session_register("username");
//session_register("password");

$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("location:administrator/student/schedule.php");
}
elseif ($stuM_count>=1){

$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("location:administrator/studentMaster/groupmgt.php");

}
elseif ($teach_count>=1){

$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("location:administrator/teacher/schedule.php");

}
elseif ($admin_count==1){

$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("location:administrator/admin/groupmgt.php");

//header("location:header.php");
}
else {

?>
<!-- alert add -->

<center>
<div id="user_message3"></div>
</center>

<!-- end -->
<?php

$error = "Please try again.";
}
}
?>

after I login with the correct username and password, I wonder why the only message that appears:

first

(It works! -- does not appears)

I wonder why I cannot pass this condition: if (@$_POST['submit']) {

have you tryed:
if (isset($_POST['submit'])) {

Member Avatar for diafol

WHile testing for the var is what you should do. I think a bigger issue for you is the quality of the js-html-php-styling mish-mash again. This code is totally unmaintainable. I believe we advised you about how to clean it up on a previous thread. If you present clean, readable code that is properly indented, then you may get a lot more help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.