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