authorise user from mysql database

Posted by Jacksta on Stack Overflow See other posts from Stack Overflow or by Jacksta
Published on 2010-04-19T07:08:28Z Indexed on 2010/04/19 7:13 UTC
Read the original article Hit count: 234

Filed under:
|
|

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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Secret Area</title>
</head>

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

</body>
</html>

© Stack Overflow or respective owner

Related posts about php

Related posts about php5