Hi, I`m having a few problems with a script and was wondering if anyone knew how I could fix it?

Basically its just repeatedly showing the login page and not setting the cookies so that I can log into the rest of the script

login.php
CODE
<?php

include "./../includes/config.php";
include "./../includes/db_mysql.php";
include "./../includes/functions.php";

$db = new DB_Sql;
$db->User=$db_user;
$db->Password=$db_password;
$db->Host=$host;
$db->Database=$dbname;


if ($action == "logout")
{
setcookie("admin_usr", '');
setcookie("admin_pwd", '');

echo $lang['admin_logged_out'];
global_login();
exit();
}

$query = "SELECT * FROM tech WHERE username='$username' and password='$password' and is_admin='1'";
$db->query($query);

if (!($user = $db->row_array()))
{
echo $lang['admin_wrong_pass'];
global_login();
}
else
{
if ($cookie == "1")
{
setcookie("admin_usr", $user[id], mktime(0,0,0,1,12,2012));
setcookie("admin_pwd", $password, mktime(0,0,0,1,12,2012));
}
else
{
setcookie("admin_usr", $user[id]);
setcookie("admin_pwd", $password);
}

echo jump('index.php', 'You have been logged in successfully');
}

?>


global.php

CODE
<?php

include "./../includes/config.php";
include "./../includes/db_mysql.php";
include "./../includes/functions2.php";

$templatecache=array();

$db = new DB_Sql;
$db->User=$db_user;
$db->Password=$db_password;
$db->Host=$host;
$db->Database=$dbname;

set_magic_quotes_runtime(0);

function stripslashesarray (&$arr)
{
while (list($key,$val)=each($arr))
{
if (is_string($val))
{
$arr[$key]=stripslashes($val);
}
if (is_array($val))
{
$arr[$key]=stripslashesarray($val);
}
}
return $arr;
}
if (get_magic_quotes_gpc() and is_array($GLOBALS))
{
$GLOBALS=stripslashesarray($GLOBALS);
}

$username = $_COOKIE["admin_usr"];
$password = $_COOKIE["admin_pwd"];

if (($username == '') || ($password == ''))
{
global_login();
}
else
{

$query = "SELECT * FROM tech WHERE id='$username' and password='$password' and is_admin='1'";
$db->query($query);
if (!($user = $db->row_array()))
{
global_login();
}

}

?>


the global_login(); function

CODE
function global_login() {

echo "<div align=\"center\"><BR />";
echo "<P><BR /><BR />";
echo table_start('Please log in', 'login.php');
$bit = textfield('username', '');
echo table_row2('USERNAME', $bit);
$bit = textpassword('password', '');
echo table_row2('PASSWORD', $bit);
$bit = yn_radio('cookie');
echo table_row2('REMEMBER COOKIE', $bit);
echo table_end();
echo "</div>";
exit();

}