Mohon bantuan Agan2 skalian, saya coba koneksi dari PHP ke DB tapi selalu ada warning spt ini :
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\asramapoliteknik\administrator\login.php on line 27
terimakasih sebelumnya utk bantuannya....
<?php
// memulai session
session_start();
include "../include/koneksi.php";
if(isset($_POST['Submit'])){
$username = $_POST['username'];
$password = $_POST['pass'];
if(empty($username)){
echo "<script type='text/javascript'>
onload =function(){
alert('Username belum diisi');
}
</script>";
}
elseif(empty($password)){
echo "<script type='text/javascript'>
onload =function(){
alert('Password belum diisi');
}
</script>";
} else {
// query untuk mendapatkan record dari username
$query = "SELECT * FROM user WHERE username = '$username'";
$hasil = mysql_query($query);
$data = mysql_fetch_array($hasil);
// cek kesesuaian password
if ($password == $data['password'])
{
header("location:index.php");
// menyimpan username dan level ke dalam session
$_SESSION['level'] = $data['level'];
$_SESSION['username'] = $data['username'];
}
echo "<script type='text/javascript'>
onload =function(){
alert('Username atau password salah!! Ulangi kembali');
}
</script>";
}
}
?>