登录表单的mysql错误消息

时间:2015-12-28 09:22:31

标签: php mysql

我是php的新手。我尝试创建PHP登录但我收到此错误消息:

  

警告:mysql_num_rows()要求参数1为resource,boolean   给出。

这是我的编码:

if(isset($_POST['submit'])){
$email = $_POST['email'];
$password = $_POST['password'];

if(empty($email) or empty($password)){
    $message = "Please fill in all fields";
} else {
    $check_login = mysql_query("SELECT id FROM form WHERE email='$email' AND password='".md5($password)."'");
    if(mysql_num_rows($check_login) == 1){
        $get = mysql_fetch_array($check_login);
        $user_id = $get['id'];
        $_SESSION['user_id'] = $user_id;

2 个答案:

答案 0 :(得分:1)

- >选择你的数据库..

//尝试此代码。

<?php

session_start();
error_reporting(0);
$con=mysql_connect('localhost','root','');
if($con)
{
//echo "success";
mysql_select_db('task_management');
}
else
{
    echo "unsuccess".mysql_error();
}

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$select = mysql_query("select * from `tablename` where `email`='$username' AND `password`='$password'");
$count=mysql_num_rows($select);

if($count>0){
   $row=mysql_fetch_object($select);
   $_SESSION['adminId']=$row->id;
   $_SESSION['username']=$row->username;
   header('location:current_task_detail.php');
}else{
   header('location:index.php');
}

?>

答案 1 :(得分:0)

$ check_login = mysql_query(“SELECT id FROM form WHERE email ='$ email'AND password ='”。md5($ password)。“'”); $ num = mysql_num_rows($ check_login);     if($ num == 1){.....