SQL query isn't executing... grr!
| From: | Todd Williamsen | Date: | Wed, 07 Nov 2001 15:32:55 +0000 |
| Subject: | SQL query isn't executing... grr! | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-10261@lists.php.net to get a copy of this message | ||
Ok, I am new to this PHP/mySQL scene, but am pretty proficient at MS based
SQL and ASP
I have a mySQL database called FF and a table called tblmembers. Now, I
wanted to do login and user authentication to the database and I came up
with this script.
What happens is that the sql query cannot execute, thus the message
"Couldn't Execute the Query"
What could be the problem? I took this tidbit out of Julie Meloni's book
"PHP Fast and Easy Web Development" and modified it to fit my needs.
(I have columns of Userid and Password)
<?php
if ((!$username) || (!$password)) {
header("Location: http://63.216.178.246/login.html");
exit;
}
$db_name = "ff";
$table_name = "tblmembers";
$connection = @mysql_connect("localhost", "admin", "lck77") or
die("Couldn't
Connect to Database.");
$sql = "SELECT * FROM $table_name WHERE Userid = \"$username\" AND Password
= password(\"$password\")";
$result = @mysql_query($sql, $connection) or die ("Couldn't Execute the
Query.");
$num = mysql_numrows($result);
if ($num != 0) {
$msg = "<p>You are Logged In!</p>";
} else { header("Location: http://63.216.178.246/login.html");
exit;
}
?>
<html>
<head>
<title>Member's Only</title>
</head>
<body>
<? echo "$msg";
?>
</body>
</html>