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


<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>






<!-- 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() {
    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: ""

    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"}
    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"


.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;




$error = "";

echo "first";

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

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

// username and password sent from form

// 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);

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

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

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

// Mysql_num_row is counting table row

// 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['username'] = $username;
$_SESSION['password'] = $password;

elseif ($stuM_count>=1){

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


elseif ($teach_count>=1){

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


elseif ($admin_count==1){

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


else {

<!-- alert add -->

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

<!-- end -->

$error = "Please try again.";

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


(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

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.