Dear Experts, I am using these codes

<?php
require_once("../includes/connectw.php");
require_once("../includes/functions.php");
$error="";
if(isset($_POST['login']))
{   
    $muser=clean($_POST['username']); 
    $mpass=clean($_POST['password']); 
    if(empty($muser))
    {
        $error="User name must not be empty";
    }
    elseif (empty($mpass))
    {
        /*echo ('<script>alert("Password must not be empty")</script>');*/
        $error="User name must not be empty";
    }
    else
    {
        $query="select * from admin where user ='".$muser."' and pass='".md5($mpass)."'";
        $result=mysqli_query($con,$query)or die ("Error". mysqli_error($con)) ;  
        $row=mysqli_fetch_array($result);
        //  echo print_r ($row);
        $count=mysqli_num_rows($result); 
        if($count==0){
            $error="Password is invalid";
        }else{

            $query = "INSERT INTO history (user,login ,logout,duration) VALUES ('".$muser."','".(date('Y-m-d H:i:s'))."' ,'".date('Y-m-d H:i:s')."', '".date('Y-m-d H:i:s')."')";

            $result=mysqli_query($con, $query) or die (mysqli_error($con));
            session_start();
            $_SESSION['v'] = 'vikas';
            $_SESSION['id'] = $row['id'];
            $_SESSION['user'] = $muser;
            $_SESSION['email'] = $memail;
            $_SESSION["startTime"] = date('Y-m-d H:i:s');

            header("location:../index.php");

        }
    }
}
?>

If user name and password is correct then page redirect to index.php.
But before session() following codes does not work

$query = "INSERT INTO history (user,login ,logout,duration) VALUES ('".$muser."','".(date('Y-m-d H:i:s'))."' ,'".date('Y-m-d H:i:s')."', '".date('Y-m-d H:i:s')."')";
            $result=mysqli_query($con, $query) or die (mysqli_error($con));

Please help

What error are you getting?

no error occurs but insert command does not work

Hello, if haven't solved yet, show us the schema of the history table, run:

SHOW CREATE TABLE `history`;

Consider that the insert cannot occour if there is a unique key on the user.

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.