I have the following code for a login page that is supposed to display an error when the user enters the wrong username and password combination. can anyone have a look at the code and tell me why it isnt displaying the error message when its supposed to.

Here is the code below:

<html>
<head>
<?php

    include "header.php";
?>
<script language="javascript" type="text/javascript">
function fun_val()
    {
        var l=document.loginsell.username.value;
        if(l=="")
        {
            alert("Please Enter User name");
            document.loginsell.username.focus;
            return false;
        }

        var p=document.loginsell.password.value;
        if(p=="")
        {
            alert("Please Enter Password");
            document.loginsell.password.focus;
            return false;
        }
    }
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>

<body bgcolor="#fff2e5" alink="#0000FF" vlink="#0000FF">

<p align="center">

<p align="center">

<p align="center">
<p align="center"><br><TR></tr>
<form name="loginform" action="loginsession.php" method="post"><TR></tr>
  <table width="400" height="178" align="center" cellpadding="1"cellspacing="1" border="3"  bordercolor="#FF0066" bgcolor="#fff2e5">
    <tr> 
      <td height="41" colspan="2" align="center"><h2><font color="#FF0000"><em><font face="Georgia, Times New Roman, Times, serif">ADMIN LOGIN</font></em></font></h2></td>
    </tr>
    <tr> 
      <td width="170" height="40"  align="center"><h3><font color="#7c0000"><em><font face="Georgia, Times New Roman, Times, serif">User Name</font></em></font></h3></td>
      <td width="213"><font color="#7c0000">
         <input type="text" name="username" style="background" />
      </font></td>
    </tr>
    <tr> 
      <td height="38" align="center"><h3><font color="#7c0000"><em><font face="Georgia, Times New Roman, Times, serif">password</font></em></font></h3></td>
      <td><font color="#7c0000">
        <input type="password" name="password" maxlength="8">
        </font></td>
    </tr>
    <tr> 
      <td height="48" colspan="2" align="center"><font color="#7c0000">
        <input type="submit"  value="Submit" name="ok" onClick="return fun_val();"/>

        </td>
      </a></font></td>
    </tr>
  </table>
<p>&nbsp;</p>
</form>

<p>
  <?php

                     if($_POST['flag']==1)
                    {
                    ?>
  <script language="JavaScript">
                            alert("Please Do Login Properly");
                        </script>
      <?
                    }
?>
</p>
<marquee behavior=alternate bgcolor="#7e0000"><b><i><a href=contectus.php><font color="white">Developed By :-  ME </a></i></b></font></marquee>
</body>
</html>

Recommended Answers

All 3 Replies

in your function you use loginsell but your form is called loginform

Thanks. I renamed everything to just the same thing but i cant get the code from line 72 to 76 to kick in. it doesnt display the error message ("Please Do Login Properly"). it just does nothing. can you tell me how to resolve this or write another code to enable the error message pop up

Member Avatar for Zagga

Hi thunder234,

I'm not sure if you solved this already but the lines you mention will only be run if the variable 'flag' is sent via $_POST. I don't see it in the code you provided. Are you sure this variable is being set and sent correctly?

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.