0

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

3
Contributors
3
Replies
37
Views
1 Year
Discussion Span
Last Post by cereal
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.