-4
$koneksi = mysqli_connect($host_name, $username, $password, $database);

$query = mysqli_query($koneksi, "SELECT * FROM pembeli");
$hasil = mysqli_query($query);

while ( $buyer = mysqli_fetch_assoc($hasil)){
    echo $buyer ['Nama'];
    echo $buyer ['Barang'];
    echo $buyer ['Retribusi'];
}

I have that line of code, its produce syntax error unexpected '$query'(T_VARIABLE). Whats wrong ?

KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
jakaperdana
  • 17
  • 1
  • 1
  • 6
  • So you put the result of `mysqli_query` in another `mysqli_query`??? – juergen d Dec 29 '17 at 10:25
  • so, what must i write? – jakaperdana Dec 29 '17 at 10:27
  • I suggest you take some time to research mysqli basics(, and spend a little time on code formatting). You're making a few odd mistakes, some research will allow you to find your own mistake in this case. – Martijn Dec 29 '17 at 10:51
  • Apart from that, we're not a site that 'just gives you the answer' – Martijn Dec 29 '17 at 10:51
  • @jakaperdana Please add the full error message to your question. Also add the full source code of the mentioned PHP file to your question. To not alter/change the source code besides removing the login data. – Progman Dec 29 '17 at 13:59
  • @jakaperdana You might want to read https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/15539535#15539535. – Progman Dec 29 '17 at 14:01

1 Answers1

1

In mysqli no need to write :- mysql_select_db($database);

because fourth param in is database name

example :- mysqli_connect($localhost, $username, $password, $database);

Update your code as shown below

$database  = "jaka_crud_ci";

$koneksi = mysqli_connect($host_name, $username, $password, $database);

$query = mysqli_query($koneksi, "SELECT * FROM pembeli");

while ( $buyer = mysqli_fetch_assoc($query)){
    echo $buyer['Nama'];
    echo $buyer['Barang'];
    echo $buyer['Retribusi'];
}
Martijn
  • 15,791
  • 4
  • 36
  • 68
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40