-1

i am new to php coding

i created login page with user name and password,the login web page is showing, when i am entering user and password it's getting error,i find many ways but i did not find any solution, it's not working,

image here

this is my error where i did mistake

this is login code

<?php include('server.php');?>)
<!DOCTYPE html>
<html>
<head>
<title> user registration system using php</title>
<link rel ="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div class ="header">
        <h2> login</h2>
    </div>
    <form method="post" action="login.php">
    <?php include('errors.php'); ?>
        <div class ="input-group">
            <label>Username</label>
            <input type = "text" name = "Username">
        </div>

        <div class ="input-group">
            <label>password</label>
            <input type = "text" name = "password">
        </div>
        <div class ="input-group">
            <button type ="submit" name ="register" class="btn">login</button>
            </div>
            <p>
                not yet a member? <a href="register.php">sign up</a>
            </p>
    </form>
    </body>
    </html> 

servercode :

<?php
session_start();
$username = "";
$email = "";
$errors = array();
$db = mysqli_connect('localhost','root','','registration');
//print_r(!empty($_POST['registration']));exit;

if (empty($_POST['registration'])){

    $username = ($_POST['username']);
    $email = ($_POST['email']);
    $password = ($_POST['password']);
    //echo 'Hi';
if (empty($username)) {
    array_push($errors, "username is required");
}
if (empty($email)) {
    array_push($errors, "email is required");
}
if (empty($password)) {
    array_push($errors, "password is required");


}

if (count($errors) == 0) {

    $sql = "INSERT INTO users (username,email,password) VALUES('$username','$email','$password')";
mysqli_query($db,$sql);
$_SESSION['username'] = $username;
$_SESSION['success'] = "you are now logged in";
header('location: index.php');

}
}

if(isset($_POST['login'])) {
    $username = ($_POST['username']);

    $password = ($_POST['password']);
    //echo 'Hi';
if (empty($username)) {
    array_push($errors, "username is required");
}

if (empty($password)) {
    array_push($errors, "password is required");

}
if (count($errors)==0) {
    $query = "SELECT * FROM users where username = '$username' AND password ='$password'";
    $result = mysqli_query($db,$query);
    if(mysqli_num_rows($result) == 1) {

        $_SESSION['username'] = $username;
$_SESSION['success'] = "you are now logged in";
header('location: index.php');
}else{
    array_push($errors, "wrong username/password combination");
        header('location: login.php');
}
    }
}


if(isset($_GET['logout'])) {
    session_destroy();
    unset($_SESSION['username']);
    header('location: login.php');
}
?>
mega6382
  • 9,211
  • 17
  • 48
  • 69
sandy
  • 3
  • 1

1 Answers1

0

Check in Html form you given name as Username and at server side you fetching value with username. There are issue with caps and small letter. remove caps of U in username in html form and replace with u.