2 回答
TA贡献1906条经验 获得超10个赞
您需要检查列的值,而不是是否返回任何行。您还应该改用准备好的语句。
$stmt = $conn->prepare("SELECT image FROM users WHERE id=?");
$stmt->bind_param("s", $id);
$stmt->execute();
$stmt->bind_result($image);
if ($stmt->fetch()) {
if (empty($image)) {
$profile_pic = "/Ramdhenu/images/default_propic.png";
} else {
$profile_pic = "/Ramdhenu/userdata/Author_images/".$image;
}
} else {
// No user by that ID
}
$stmt->close();
TA贡献1843条经验 获得超7个赞
您将始终获得 $pro_num !=0 ,如果您对列进行图像处理,则需要检查默认值,假设默认值为 NULL ,
$check_pic = mysqli_query($conn,"SELECT image FROM users WHERE id='$id'");
$get_pic_row = mysqli_fetch_assoc($check_pic);
$profile_pic_db = $get_pic_row['image'];
$pro_num = mysqli_num_rows($profile_pic_db);
if($pro_num == 1){
if ($profile_pic_db == null) {
$profile_pic = "http://localhost/Ramdhenu/images/default_propic.png";
} else {
$profile_pic = "http://localhost/Ramdhenu/userdata/Author_images/".$profile_pic_db ;
}
}else{
//user not found
}
- 2 回答
- 0 关注
- 130 浏览
添加回答
举报