致命错误:未捕获错误:在布尔值上调用成员函数fetch_assoc()

时间:2016-08-15 06:47:02

标签: php html mysql database

我正在尝试在连接到我的数据库时创建日志,但是我收到此错误:

  

致命错误:未捕获错误:在布尔值上调用成员函数fetch_assoc()

以下是代码:

<?php 

include 'database.php';
?>

<?php

// create a variable
$email=$_POST['email'];
$password=$_POST['password'];


//Execute the query

$sql = "SELECT * FROM user WHERE email='$email' AND password='$password'";
$result = mysqli_query($connect,$sql);

if(!$row = $result -> fetch_assoc($result)){
    echo "Your email or password is incorrect!";
    }
    else{
    echo "You are logged in!";
    }

谢谢!

2 个答案:

答案 0 :(得分:0)

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <lua.hpp>

#ifdef __cplusplus
  extern "C" {
#endif

void test_func_a ( void ) {
  printf ( "hello\n" );
}

#ifdef __cplusplus
  }
#endif

int main ( int argc, char** argv ) {
  lua_State *lua = luaL_newstate();
  assert ( lua );
  luaL_openlibs ( lua );
  const int status = luaL_dostring ( lua, lua_script_content );

  if ( status )
    printf ( "Couldn't execute LUA code: %s\n", lua_tostring ( lua, -1 ));

  lua_close ( lua );

  return 0;

http://php.net/manual/en/mysqli-result.fetch-assoc.php

示例2,使用mysqli_query功能的地方。

答案 1 :(得分:0)

如果您要实现登录代码,请尝试使用

$sql = "SELECT * FROM user WHERE email='$email' AND password='$password'";
$result = mysqli_query($connect,$sql);

if(mysqli_num_rows($result) == 1 ){
    echo "You are logged in!";
    }
    else{
    echo "Your email or password is incorrect!!";
    }