too long

I'm currently working on a log-out system, which will record users when they logged out. But it's not updating properly.

Code:

<?php
include('global.php');
        $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and 
        password='$mypassword'";
    $result=mysql_query($sql);
    while($row=mysql_fetch_array($result))

        {
    $logintime=$row['logintime'];
    }


        if(mysql_num_rows($result))
        {

        $query = "UPDATE time_tb SET ";


            $query = $query."logoutime='".$p_time."' ";

            $query = $query."WHERE logintime='".$logintime."'"; 

            ExecuteQuery($query);




session_destroy();
header ("location: loginadmin.php");
            }
?>

try this

 $query = "UPDATE time_tb SET ";
 $query.="logoutime=".$p_time." WHERE logintime=".$logintime;

And yes you should check your sql query in console by using print_r or others in your code.