Im doing a login facility for my website iv connected it to the database but when i try to enter some values for login name and password i get the following message:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/milkitshakeit.freehostia.com/log.php on line 16
Here is my php code. Please can anyone help. Thank you in advance for your help:
<?
session_name("MyLogin");
session_start();
if($_GET == "login") {
$conn = mysql_connect("localhost","username","psswd"); // wrote these like this for security reasons while the post is up
$db = mysql_select_db("pukakh_user"); //put your database name in here
$name = $_POST;
$q_user = mysql_query("SELECT * FROM USERS WHERE login='$name'");
if(mysql_num_rows($q_user) == 1) {
$query = mysql_query("SELECT * FROM USERS WHERE login='$name'");
$data = mysql_fetch_array($query);
if($_POST == $data) {
session_register("name");
header("Location: http://milkitshakeit.freehostia.com"); // success page. put the URL you want
exit;
} else {
header("Location: login.php?login=failed&cause=".urlencode('Wrong Password'));
exit;
}
} else {
header("Location: login.php?login=failed&cause=".urlencode('Invalid User'));
exit;
}
}
// if the session is not registered
if(session_is_registered("name") == false) {
header("Location: login.php");
}
?>
</body>
</html>