【发布时间】:2013-11-30 09:07:26
【问题描述】:
<?php
session_start();
include('config.inc'); //for selecting database and connecting to phpmyadmin
$redirect_page = "Login_page.php";
if(isset($_POST['email']) && isset($_POST['password'])){
$email = $_POST['email'];
$password =$_POST['password'];
//$_SESSION['email'] = $email;
//$_SESSION['password'] = $password;
if((!empty($email)) && (!empty($password))){
$query = "SELECT * FROM 'login_details' WHERE (email ='".mysql_real_escape_string($email)."') AND (password ='".mysql_real_escape_string($password)."')";
$sql_query_run = mysql_query($query);
if(mysql_num_rows($sql_query_run) == 1){
echo "<div>login Success</div>";
}
else{
echo "<div>Invalid</div>";
}
}
else{
header ('Location:'.$redirect_page);
}
}
?>
我正在使用 Xampp 开发 Localhost。 上面的代码没有检查所需的最里面的“if”条件,我收到一个警告,它输出“无效”,这是最里面的“else”部分,即使我输入了数据库中存在的正确电子邮件和密码。 警告说:警告:mysql_num_rows() 期望参数 1 是资源,布尔值在第 40 行的 C:\xampp\htdocs\check_user.php 中给出 上面的代码在 check_user.php 页面中,我有一个不同的登录页面 (Login_page.php),它有一个带有方法 =“post”和操作 =“user_check.php”的 html 表单。 请帮忙...
【问题讨论】:
-
$sql_query_run = mysql_query($query,$connection);
-
mysql_*函数不再维护,不应在任何新代码库中使用。它正在逐步淘汰,以支持更新的 API。相反,您应该将prepared statements 与PDO 或MySQLi 一起使用。 -
回显您的 $query 并在 phpmyadmin 中运行。也 FROM 'login_details' 应该是 FROM
login_details即不要放单引号 -
您是否尝试将 $sql_query_run = mysql_query($query); 更改为 $sql_query_run = mysql_query($query,$con); 其中 $ con是你的link_identifier
-
我用过这个,现在它工作了---->$sql_query_run = mysql_query($query) or die (mysql_error());