doulai2025
2017-11-10 10:36
浏览 186
已采纳

警告:mysqli_fetch_assoc()期望参数1为mysqli_result,

I have this warning but I have not found what causes this error, please guys can you light me? The error is in line 58 ---> $data = mysqli_fetch_assoc($result) or die();{ I searched for a while but can't find how i tacle that error called.

"Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:.... on line 58"

<?php
require_once('connect.php');

$user_id = 0;

function print_header($title="Header") { ?>

<title>PDS</title>


<html>
<body>

<?php 


global $user_id;
if (logged_in()){
    $session_user_id = $_COOKIE['pds-usn'];
    $user_data = user_data($session_user_id, 'id', 'name', 'hashed_pw', 'email', 'last_name', 'email', 'site', 'level', 'joined', 'posts', 'type');
    echo $user_data['name'];
    echo 'U bent ingelogd als '.$_COOKIE['pds-usn'].'. <a href="login.php?logout=1">Uitloggen</a>';
}   else {
    echo "U bent niet ingelogd. <a href='login.php'>Login</a> of <a href='register.php'>registreer</a>.";
}



?>


<?php }


function print_footer() { ?>

</body>
</html>

<?php }

function user_data($user_id) {

include('connect.php');

$data = array();
$user_id = (int)$user_id;

$func_num_args = func_num_args();
$func_get_args = func_get_args();

if ($func_num_args > 0) {
    unset($func_get_args[0]);

    $fields = '`' . implode('`, `', $func_get_args) . '`';
    $sql = "SELECT $fields FROM users WHERE id = $user_id";
    $result = mysqli_query($connect, $sql);
    $data = mysqli_fetch_assoc($result) or die();
    return $data;

}   
}else {
    return false;
}

?>

Connect.php:

<?php

$connect = mysqli_connect("localhost", "root", "password") or die(header('Location: errorpage.php?error=2'));
mysqli_select_db($connect, "pds_news_feed") or die(header('Location: errorpage.php?error=3'));
?>

1条回答 默认 最新

相关推荐 更多相似问题