用户登陆验证不成功

好难啊,谁来帮帮我,用户登陆验证不成功,帮我看下是哪里出错了,非常感谢!
<?php
session_start();
require_once('connect.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<?php
$username=$_POST['username'];
$password=$_POST['password'];
$checkcode=$_POST['checkcode'];
$sql="select id,username,password from member where username='$username' and password='$password'";
$row=mysql_fetch_array($result);
$id=$row[0];
if($checkcode != reg_check_code || empty($checkcode)){
echo "<script>alert('验证码不正确,请重新输入');window.location='index.php'</script>";
exit;
}
if($username!=$row[1] || $password!=$row[2]){
echo "<script>alert('用户名或密码有误,请重新输入');window.location='index.php'</script>";
exit;
}
?>
</body>
</html>