I'm having issues with the mysql_query function in php, the exact problem its within this code
function cierraSesion($cookie) {
    $fecha = date("Y-m-d");
    $hora = date("H:i:s");
    global $connection;
    $query = "UPDATE conection SET FEC_DESCONEXION = '$fecha', FEC_HORADESCON = '$hora' WHERE VAR_COOKIE = '$cookie'";
    mysql_query($query, $connection) or die("error:" . mysql_error());
    }
when i execute this code i get this error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in
Now, you can think its a problem with the "$connection" variable but i use the exact same variable in the other 60 functions in that same file without any problem, i've checked the query making an output with die($query) and execute it manually to check any query mistake, but works fine.
Here is an example of a working function:
function abrirSesion($nombre, $sesion) {
    $fecha = date("Y-m-d");
    $hora = date("H:i:s");
    $fechaf = date("Y-m-d", strtotime("+30 minutes"));
    $horaf = date("H:i:s", strtotime("+30 minutes"));
    global $connection;
    $ip = get_client_ip();
    $query = "INSERT INTO conection (VAR_IDUSUARIO, FEC_CONEXION, FEC_HORACONEX, FEC_DESCONEXION, FEC_HORADESCON, VAR_IP, VAR_COOKIE)
                  VALUES ('$nombre', '$fecha', '$hora', '$fechaf', '$horaf', '$ip', '$sesion');";
    mysql_query($query, $connection) or die("error:" . mysql_error());
}
Thanks for any help you can give me.
 
     
     
    