Postingan lainnya
mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given maksudnya apa ya
saya pengen mengambil data dari database dan ditampilkan tapi keluar tulisan mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given dan undefined variable
saya ikutin tutorial gitu dan ditutorial itu authornya ga globalin variabel tapi bisa jalan webnya.
kodingannya kira-kira gini
<?php require "../login/dbconf.php";
$dbconn = mysqli_connect($host, $username, $password, $db_name);
function clean($str){
global $dbconn;
$str = trim($str);
$str = stripslashes($str);
$str = htmlentities($str, ENT_QUOTES);
$str = mysqli_real_escape_string($dbconn, $str);
return $str;
}
if( isset( $_SESSION['username'])){
$thisUser = clean($_SESSION['username']);
}
?>
<html>
//somecoding
$sql2 = "SELECT `templates` FROM `members` WHERE `username` = '".$thisUser."'";
$query2 = mysqli_query($dbconn, $sql2);
$row = mysqli_fetch_assoc($query2);
echo $row['templates'];
</html>
$thisUSer jadi undefined variable dan saya coba nyari debug dengan
if (!$query2) {
echo 'MySQL Error: ' . mysqli_error();
exit;
}
dan webnya blank berarti query 2 ga ada resultsnya, kira-kira apa yang salah ya?
1 Jawaban:
$array = array();
$sql2 = "SELECT `templates` FROM `members` WHERE `username` = '".$thisUser."'"; $query2 = mysqli_query($dbconn, $sql2); if($query2) { while($row = mysqli_fetch_assoc($query2)) { $array['templates'] = $row['templates']; } return $array; }