mysqli_fetch_assoc()中的错误要求参数1为mysqli_result,给定布尔值

时间:2016-05-16 06:55:28

标签: php

这是我的代码

if(isset($_POST['uploadimg'])){
move_uploaded_file($_FILES['file']['tmp_name'], "uploade_profileim/".$_FILES['file']['name'] );
$conn = mysqli_connect("localhost", "root", "", "IMDstagram");
$query = mysqli_query($conn, "UPDATE users SET profileimage = '". $_FILES['file']['name']."'WHERE username = '". $_SESSION['loggedIn']."'");
}


$conn = mysqli_connect("localhost", "root", "", "IMDstagram");
$query = mysqli_query($conn, "SELECT * FROM users WHERE username = :username");
while ($row = mysqli_fetch_assoc($query)){
    if ($row['image'] == "") {
        echo "<img src='//placeholdit.imgix.net/~text?txtsize=9&txt=100%C3%97100&w=100&h=100' class='avatar img-circle' alt='avatar'>";
    }else{
        echo "<img src 'uploaded_profileimg/".$row['profileimage']."' class='avatar' alt='profile_image'";
    }
}

?>

有人能看出我做错了吗?我不是PHP英雄。这是一个学校项目。我必须创建一个编辑profilepicture框。

1 个答案:

答案 0 :(得分:-2)

您的代码应该是这样的

    if(isset($_POST['uploadimg'])){ move_uploaded_file($_FILES['file']['tmp_name'], "uploade_profileim/".$_FILES['file']['name'] ); $conn = mysqli_connect("localhost", "root", "", "IMDstagram"); $query = mysqli_query($conn, "UPDATE users SET profileimage = '". $_FILES['file']['name']."'WHERE username = '". $_SESSION['loggedIn']."'"); }


    $conn = mysqli_connect("localhost", "root", "", "IMDstagram"); 
$query = mysqli_query($conn, "SELECT * FROM users WHERE username = '". $_SESSION['loggedIn']."'");
 while ($row = mysqli_fetch_assoc($query)){
        if ($row['image'] == "") {
            echo "<img src='//placeholdit.imgix.net/~text?txtsize=9&txt=100%C3%97100&w=100&h=100' class='avatar img-circle' alt='avatar'>";
        }else{
            echo "<img src 'uploaded_profileimg/".$row['profileimage']."' class='avatar' alt='profile_image'";
        } }

    ?>

你忘了用户会话......:)