tags:

views:

16

answers:

1

I suck at php, and cant find the error here. The script gets 2 variables "username" and "password" from a html from then check them against a MySQL databse. When I run this I get the follow error "Query was empty"

<?
if ((!$_POST[username]) || (!$_POST[password])) {
    header("Location: show_login.html");
    exit;
}
$db_name = "testDB";
$table_name = "auth_users";
$connection = @mysql_connect("localhost", "admin", "pass") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$slq = "SELECT * FROM $table_name WHERE username ='$_POST[username]' AND password = password('$_POST[password]')";
$result = @mysql_query($sql, $connection) or die(mysql_error());
$num = mysql_num_rows($result);
    if ($num != 0) {
        $msg = "<p>Congratulations, you're authorised!</p>";
    } else {
        header("Location: show_login.html");
        exit;
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Secret Area</title>
</head>

<body>
<? echo "$msg"; ?>   

</body>
</html>
+3  A: 

You're passing $sql to mysql_query but you actually stored the query in $slq

Matt
+1 hehe what a catch!!!!
OM The Eternity
thanks a heap! It would have taken me 3 hours to pick that!
Jacksta