Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi

I have a login form, when i tried to login i got this two errors:
Notice: Undefined index: username in C:\wamp64\www\FormTutorial\php\luana_login.php on line 6
Notice: Undefined index: password in C:\wamp64\www\FormTutorial\php\luana_login.php on line 7

I have been busting my head to figure out how to solve it so I went online to see if I can find a solution to fix the errors and I came across. I dont know how effective it is so
I have decide to give a tried to see how it work but this things when i put in my codes the errors gone but it give me a blank page when it should have give me the login form
to which i should be able to login.

this is the codes that I tried to use:

PHP
$username = @mysql_real_escape_string($_POST['user_name']);//when i add the code the errors is gone but give me a blank
$password = @mysql_real_escape_string($_POST['password']);


What I have tried:

PHP
<pre>this is my codes below for the login form
<?php
        // capture values from the form and store in php variables
        $uname=($_POST['username']);
        $pword=($_POST['password']);
        //connection to the database
        $db_host='localhost';
        $db_username='root';
        $db_password="";
        $con=mysqli_connect($db_host, $db_username, $db_password) or die (mysqli_connect_error());
        //select the database to query
        mysqli_select_db($con, 'staff') or die (mysqli_error($con));
        $sql="SELECT * FROM applicant  WHERE uname ='$uname' AND pword=md5('$pword')";
        $result=mysqli_query($con,$sql) or die ("Error:" .mysqli_error($con));
        $rowcount=mysqli_num_rows($result);
        if($rowcount == 1)
        {
            session_start();
            $_SESSION['user']=$username;
            header("location:luana_profile.php");
        }
        else
        {
            echo"<script type=\"text/javascript\">
            alert('username and password doesn't exist');
            window.location\"../xhtml/luana_login.html\";
            </script>";

}
mysqli_close($con);
Posted
Updated 13-May-18 11:02am

1 solution

In your source code there is $_POST["user_name"] and $_POST["username"] is used. I am guessing
username
is incorrect. But, check with your form.

Using this way may not be the best method. Try using mysqli_stmt related functions, better yet use the class.

It looks like you are starting your session in the middle of your page, your configuration will alliw this, but may not be the best practice.

Using @ at your source is bad idea and can lead to disastrous situation. DO NOT USE THEM
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900