<?php
ob_start();
session_start();
include_once('koneksi2.php');
//$message=array();
if(isset($_POST['username']) && !empty($_POST['username'])){
    $username=mysql_real_escape_string($_POST['username']);
}else{
    $message[]='Please enter username';
}

if(isset($_POST['password']) && !empty($_POST['password'])){
    $password=mysql_real_escape_string($_POST['password']);
}else{
    $message[]='Please enter password';
}

$countError=count($message);
$ids=$_POST['id'];
if($countError > 0){
     for($i=0;$i<$countError;$i++){
              echo ucwords($message[$i]).'<br/><br/>';
     }
}else{
    $query="select * from tab_user where username='$username' and password='$password'";

    $res=mysql_query($query);
    $checkUser=mysql_num_rows($res);
    $row=mysql_fetch_array($res);
    
    if($checkUser > 0){
         /*$_SESSION['LOGIN_STATUS']=true;*/
         
         
         $_SESSION['username']=$username;
         $_SESSION['password']=$password;
         
         setcookie('username', $row['username'], time() + 1*24*60*60,"/");
         setcookie('password', $row['password'], time() + 1*24*60*60,"/");
         
    $update=mysql_query("update tab_user set id_signal='$ids' where username='$username'");

          echo 'true';
          

    }else{
         echo ucwords('please enter correct user details');
    }
     
}
ob_end_flush();
?>

