0

I am new to PHP and i am trying to develop a small application in it. Received an undefined index error, tried to set the path right however could not overcome this error. It would be great if someone could help me solve this error. Please find the code attached below.

ERROR:Undefined index: uname in D:\wamp64\www\bbms\loginCheck.php ERROR:Undefined index: upass in D:\wamp64\www\bbms\loginCheck.php on line 4

1.header.php

<html>
<body>
    <frameset cols="20%,*">
        <frame name="logo">
            <a href="index.html"><img src="images/logo.jpg" width="20%"   height="30%"/></a>
        </frame>
        <frame name="login">
           <?php include('login.php');?>

        </frame>
</body>
</html>

2.login.php

 <html>
 <head>

    <script type="text/javascript" language="JavaScript">
        function validate()
        {
                   if(document.getElementByName("uname").value==""||document.getElementByName("upass").value=="")
                {
                        document.getElementById("msg").innerHtml="Donor Login and password must not be left empty";
                        document.getElementByName("uname").focus();
                        document.getElementByName("upass").focus();
                }
                else
                {
                    <?php header('Location:loginCheck.php');?>
                }
        }
    </script>
    <?php
            if (isset($_GET['msg'])) {
                        $msg=$_GET['msg'];

            }
            else
                $msg="";
    ?>
</head>
<body>

    <p id="msg"><?php echo $msg;?></p>
    <form method="post">
        Donor Login<input type="text" name="uname" value="Enter your login id"><br>
        Password<input type="password" name="upass" value="Enter the password"><br>
        <a href="forgotPassword.php">Forgot Password?</a><br>
        <input type="submit" value="Login" onClick="validate()"/>
    </form>
</body>
</html>

3.loginCheck.php

<?php

$uname=$_REQUEST["uname"];
$upass=$_REQUEST["upass"];
if($uname==""||$upass=="")
{
    //echo "Must not be empty";
    header('Location:header.php?msg=Donor Login and password must not be left empty');
}
else if($uname=="admin"&&$upass=="admin")
{
        session_start();
        echo "Welcome user";
}
else
{
    header('Location:login.php?msg=Invalid Login');
}
?>
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Masivuye Cokile Mar 22 '17 at 10:53

2 Answers2

0

I think its not getElementByName it should be getElementsByName.

Please keep this source to cross check your syntaxes from next time.

Here is the link.

Rahul
  • 18,271
  • 7
  • 41
  • 60
0

loginCheck.php should be the action of your form and not a redirect in the validate() function.

Try this way.

<html>
 <head>

    <script type="text/javascript" language="JavaScript">
        function validate()
        {
                   if(document.getElementByName("uname").value==""||document.getElementByName("upass").value=="")
                {
                        document.getElementById("msg").innerHtml="Donor Login and password must not be left empty";
                        document.getElementByName("uname").focus();
                        document.getElementByName("upass").focus();
                        return false
                }
                return true
        }
    </script>
    <?php
            if (isset($_GET['msg'])) {
                        $msg=$_GET['msg'];

            }
            else
                $msg="";
    ?>
</head>
<body>

    <p id="msg"><?php echo $msg;?></p>
    <form method="post" action="loginCheck.php" onsubmit="return validate()">
        Donor Login<input type="text" name="uname" value="Enter your login id"><br>
        Password<input type="password" name="upass" value="Enter the password"><br>
        <a href="forgotPassword.php">Forgot Password?</a><br>
        <input type="submit" value="Login" onClick="validate()"/>
    </form>
</body>
</html>
napolux
  • 15,574
  • 9
  • 51
  • 70