<?php
ob_start();
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="****"; // Mysql password
$db_name="users"; // Database name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $email and $password
$email= $_POST['email'];
$password= md5($_POST['password']);
$check="SELECT * FROM 'login' WHERE 'email'='$email' and 'password'='$password'";
$result=mysql_query($check);
// Mysql_num_row is counting table row
$count = mysql_num_rows($result); // This is line 20 where it keeps complaining.
// If result matched $email and $password, table row must be 1 row
if($row==1){
// Register $email, $password and redirect to file "login_success.php"
session_register("email");
session_register("password");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
I have spent around 3 hours trying to fix the problem, and trawling through many google sites. I cannot find what the problem is. Any help would be much appreciated.
Answer this Question$check="SELECT * FROM 'login' WHERE 'email'='$email' and 'password'='$password'";
Don't use 'single quotes' around identifiers for tables/columns, use `back quotes` instead.
OR
最后查出来的结论是我的SQL语句FROM后面只写了table的名字,没写database的名字,加上之后就好了。
SELECT * FROM DB_NAME.TABLE WHERE... ...