-1

When I am submitting the form then I am landing on login.php and getting so many errors.

I have put errors on following link: https://docs.google.com/document/d/1AqwZ71iAQgZGMU-W0Go6czbpgGenF_f7ucgmEFw0AHo/edit

I am newbie and struggling for last 5 hours with above code. I have following pages in my login logout system:

db.php

<?php 
$conn=new mysqli('localhost','root','','people');
?>

index.php

    <?php
    session_start();
    ?>
    <html>
    <head></head>
    <body>
    <form method="post" name="login" action="login.php">
    <label for="name" class="labelname"> Username </label>
    <input type="text" name="username" id="userid" required="required" /><br />
    <label for="name" class="labelname"> Password </label>
    <input type="password" name="password" id="passid" required="required"  /><br />
    <input type="submit" name="submit" id="submit"  value="Login" />
    </form>
    </body>
</html>

login.php

<?php 
include('db.php');
session_start();
{
    $user=mysqli_real_escape_string($_POST['username']);
    $pass=mysqli_real_escape_string($_POST['password']);
    $fetch=mysqli_query("SELECT id FROM `user` WHERE 
                         username='$user' and password='$pass'");
    $count=mysqli_num_rows($fetch);
    if($count!="")
    {
    session_register("sessionusername");
    $_SESSION['login_username']=$user;
    header("Location:profile.php"); 
    }
    else
    {
       header('Location:index.php');
    }}
?>

logout.php

<?php
session_start();
if(session_destroy())
{
header("Location: index.php");
}
?>

session.php

<?php
include('db.php');
session_start();
$check=$_SESSION['login_username'];
$session=mysqli_query("SELECT username FROM `user` WHERE username='$check' ");
$row=mysqli_fetch_array($session);
$login_session=$row['username'];
if(!isset($login_session))
{
header("Location:index.php");
}
?>

profile.php

<?php
include('db.php');
session_start();
$check=$_SESSION['login_username'];
$session=mysqli_query("SELECT username FROM `user` WHERE username='$check' ");
$row=mysqli_fetch_array($session);
$login_session=$row['username'];
if(!isset($login_session))
{
header("Location:index.php");
}
?>
user3811050
  • 467
  • 1
  • 3
  • 12

1 Answers1

0

I think there is something wrong with your db.php file. You are only supposed to pass 3 parameters,viz, servername, username and password, whereas I see you are passing 4, one being blank.

Please check if

 <?php 

$conn=new mysqli('localhost','root','people'); ?>

or

 <?php 

$conn=new mysqli('localhost','',''); ?>

works.

user299567
  • 26
  • 3