syntax ?> untuk end of file apa ya di php

<?php require_once 'config.php';
$dbConn = mysqli_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysqli_error());mysqli_select_db($dbConn, $dbName) or die('Cannot select database. ' . mysqli_error());
function dbQuery($sql){    $sql = ['SELECT uid, uname, utype FROM tbl_users '];    $result = mysqli_query ("SELECT * from tbl_users where username='$dbUser' and password='$dbPass') or die(mysqli_connect_error());        return $result;}
function dbAffectedRows(){    global $dbConn;        return mysqli_affected_rows($dbConn);}
function dbFetchArray($result, $resultType = MYSQLi_NUM) {    return mysqli_fetch_array($result, $resultType);}
function dbFetchAssoc($result){    return mysqli_fetch_assoc($result);}
function dbFetchRow($result) {    return mysqli_fetch_row($result);}
function dbFreeResult($result){    return mysqli_free_result($result);}
function dbNumRows($result){    return mysqli_num_rows($result);}
function dbSelect($dbName){    return mysqli_select_db($dbName);}
function dbInsertId(){    return mysqli_insert_id();}?>

berikut error nya:
Parse error: syntax error, unexpected end of file in B:\xampp baru\htdocs\asset_management\library\database.php on line 55

mohon bantuan nya, apa yang harus ditambahkan pada syntax ?> agar bisa tutup?
avatar marissafiddarayni

@marissafiddarayni

4 Kontribusi 3 Poin

  • coba kirim potongan kode-nya sebagai "script", jangan sebagai teks biasa, untuk membaca potongna kodenya agak susah - @ahanafi


Jawaban

Ini coba saya betulkan dan rapihkan:
<?php require_once 'config.php';
$dbConn = mysqli_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysqli_error());
mysqli_select_db($dbConn, $dbName) or die('Cannot select database. ' . mysqli_error());
function dbQuery($sql){
    $sql = ['SELECT uid, uname, utype FROM tbl_users '];
    $result = mysqli_query("SELECT * from tbl_users where username='$dbUser' and password='$dbPass'") or die(mysqli_connect_error());
    return $result;
}
function dbAffectedRows(){
    global $dbConn;
    return mysqli_affected_rows($dbConn);
}
function dbFetchArray($result, $resultType = MYSQLi_NUM) {
    return mysqli_fetch_array($result, $resultType);
}
function dbFetchAssoc($result){
    return mysqli_fetch_assoc($result);
}
function dbFetchRow($result) {
    return mysqli_fetch_row($result);
}
function dbFreeResult($result){
    return mysqli_free_result($result);
}
function dbNumRows($result){
    return mysqli_num_rows($result);
}
function dbSelect($dbName){
    return mysqli_select_db($dbName);
}
function dbInsertId(){
    return mysqli_insert_id();
}
?>

Penjelasan:
Yang jadi masalah adalah di variable $result.
$result = mysqli_query ("SELECT * from tbl_users where username='$dbUser' and password='$dbPass') or die(mysqli_connect_error());

Di function mysqli_query() anda kurang teliti dengan menambahkan tanda petik ganda, yang benar adalah seperti ini:
$result = mysqli_query("SELECT * from tbl_users where username='$dbUser' and password='$dbPass'") or die(mysqli_connect_error());

Semoga cepat paham dan membantu.
avatar syahid246

@syahid246

70 Kontribusi 160 Poin


Login untuk gabung berdiskusi