Postingan lainnya
mohon bantuan nya mengatasi masalah ini
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp_7.4.7\htdocs\Aset\login.php on line 82
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp_7.4.7\htdocs\Aset\login.php on line 83
scripnya :
ob_start();
?>
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang=""> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Pengelolaan Aset</title>
<meta name="description" content="Sufee Admin - HTML5 Admin Template">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="images/logo3.png">
<link rel="shortcut icon" href="images/logo3.png">
<link rel="stylesheet" href="assets/css/normalize.css">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/themify-icons.css">
<link rel="stylesheet" href="assets/css/flag-icon.min.css">
<link rel="stylesheet" href="assets/css/cs-skin-elastic.css">
<!-- <link rel="stylesheet" href="assets/css/bootstrap-select.less"> -->
<link rel="stylesheet" href="assets/scss/style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> -->
</head>
<body class="bg-dark">
<div class="sufee-login d-flex align-content-center flex-wrap">
<div class="container">
<div class="login-content">
<div class="login-logo">
<a href="index.php">
<img class="align-content" alt="">
</a>
</div>
<div class="login-form">
<form method="post">
<div class="form-group">
<label>Username</label>
<input type="text" name="username" class="form-control" placeholder="Username" >
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control" placeholder="Password" >
</div>
<div class="form-group">
<label > Level </label>
<select class="form-control" name="level" id="level">
<option value="Admin">Admin</option>
<option value="Karyawan">Karyawan</option>
<option value="Keuangan">Keuangan</option>
<option value="Pimpinan">Pimpinan</option>
</select>
</div>
<button type="submit" name="login" class="btn btn-info btn-flat m-b-30 m-t-30">Login</button>
<div class="register-link m-t-15 text-center">
<p></p>
<p><a href="forget.php"> Lupa Password</a></p>
</div>
</form>
<?php
include ('koneksi.php');
if (isset($_POST['login'])) {
$user=$_POST['username'];
$pass=$_POST['password'];
$level=$_POST['level'];
$query=mysqli_query($connect, "SELECT * from user WHERE username='$user' AND password='$pass' AND level='$level'");
$hasil=mysqli_num_rows($query);
$data=mysqli_fetch_array($query);
if ($hasil) {
session_start();
$_SESSION['username']=$data['nama'];
$_SESSION['id']=$data['id_user'];
$_SESSION['level']=$data['level'];
header("location:index.php");
}
else
echo "<script>alert('Periksa data dengan Benar')</script>";
}
?>
</div>
</div>
</div>
</div>
<script src="assets/js/vendor/jquery-2.1.4.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/plugins.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>
Tanggapan
Bisa di format codinganya gan biar lebih mudah di baca
1 Jawaban:
<div>Halo sebelumnya coba ketika membuat thread baca panduannya terlebih dahulu disini <a href="https://sekolahkoding.com/forum/filter/rules#betterQuestion">https://sekolahkoding.com/forum/filter/rules#betterQuestion</a><br><br>Untuk error-nya coba cek lagi penulisan querynya, cek nama tabelnya, apakah user atau users ? Kalo berdasarakan dari errornya, itu ada kesalahan pada penulisan querynya.<br>Untuk mengetahui keterangan errornya, coba ganti baris berikut :<br><br></div><pre><strong>$query=mysqli_query($connect, "SELECT * from user WHERE username='$user' AND password='$pass' AND level='$level'");</strong></pre><div><br>menjadi :<br><br></div><pre><strong>$query=mysqli_query($connect, "SELECT * from user WHERE username='$user' AND password='$pass' AND level='$level'") or die(mysqli_error($connect));</strong></pre>