Fatal error: Uncaught mysqli_sql_exception: Unknown column ‘carikrowo’ in ‘where clause’ in C:xampphtdocsData Ipedaproses-login.php:10
Stack trace:
#0 C:xampphtdocsData Ipedaproses-login.php(10): mysqli->prepare(‘SELECT * FROM p…’)
#1 {main} thrown in C:xampphtdocsData Ipedaproses-login.php on line 10
here is the process-login.php full code
<?php
session_start();
require_once("database.php");
if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM pengguna WHERE username = :username and password = :password";
$stmt = $db->prepare($sql);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);
}
// Check if the user exists
if ($user) {
// Verify hashed password
if (password_verify($password, $user["password"])) {
// Create a session
$_SESSION["pengguna"] = $user;
if ($user['jabatan'] == "Carik") {
// Set session variables for admin
$_SESSION['username'] = $username;
$_SESSION['jabatan'] = "Carik";
// Redirect to admin dashboard
header("location: halaman_admin.php");
exit();
} elseif ($user['jabatan'] !== "Carik"){
// Redirect to user dashboard
header("location: halaman_user.php");
exit();
}
} else {
// Redirect back to login page with an error message
header("Location: form-login.php?error=invalid");
exit();
}
} else {
// Redirect back to login page with an error message
header("Location: form-login.php?error=invalid");
exit();
}
?>
and here is form-login.php
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<style>
img{
width: 100%;
}
.login {
height: 1000px;
width: 100%;
background: radial-gradient(#653d84, #332042);
position: relative;}
.login_box {
width: 1050px;
height: 600px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
background: #fff;
border-radius: 10px;
box-shadow: 1px 4px 22px -8px #0004;
display: flex;
overflow: hidden;
}
.login_box .left{
width: 41%;
height: 100%;
padding: 25px 25px;
}
.login_box .right{
width: 59%;
height: 100%
}
.left .top_link a {
color: #452A5A;
font-weight: 400;
}
.left .top_link{
height: 20px
}
.left .contact{
display: flex;
align-items: center;
justify-content: center;
align-self: center;
height: 100%;
width: 73%;
margin: auto;
}
.left h3{
text-align: center;
margin-bottom: 40px;
}
.left input {
border: none;
width: 80%;
margin: 15px 0px;
border-bottom: 1px solid #4f30677d;
padding: 7px 9px;
width: 100%;
overflow: hidden;
background: transparent;
font-weight: 600;
font-size: 14px;
}
.left{
background: linear-gradient(-45deg, #dcd7e0, #fff);
}
.submit {
border: none;
padding: 15px 70px;
border-radius: 8px;
display: block;
margin: auto;
margin-top: 120px;
background: #583672;
color: #fff;
font-weight: bold;
-webkit-box-shadow: 0px 9px 15px -11px rgba(88,54,114,1);
-moz-box-shadow: 0px 9px 15px -11px rgba(88,54,114,1);
box-shadow: 0px 9px 15px -11px rgba(88,54,114,1);
}
.right {
background: linear-gradient(212.38deg, rgba(242, 57, 127, 0.7) 0%, rgba(175, 70, 189, 0.71) 100%),url(https://static.seattletimes.com/wp-content/uploads/2019/01/web-typing-ergonomics-1020x680.jpg);
color: #fff;
position: relative;
}
.right .right-text{
height: 100%;
position: relative;
transform: translate(0%, 45%);
}
.right-text h2{
display: block;
width: 100%;
text-align: center;
font-size: 50px;
font-weight: 500;
}
.right-text h5{
display: block;
width: 100%;
text-align: center;
font-size: 19px;
font-weight: 400;
}
.right .right-inductor{
position: absolute;
width: 70px;
height: 7px;
background: #fff0;
left: 50%;
bottom: 70px;
transform: translate(-50%, 0%);
}
.top_link img {
width: 28px;
padding-right: 7px;
margin-top: -3px;
}
</style>
<body>
<section class="login">
<div class="login_box">
<div class="left">
<div class="contact">
<form action="proses-login.php" method="post">
<h3>LOG IN</h3>
<input type="text" name="username" id="username" placeholder="USERNAME">
<input type="password" name="password" id="password" placeholder="PASSWORD">
<button type="button" id="showPassword">Lihat Password</button>
<script>
document.addEventListener("DOMContentLoaded", function() {
const passwordInput = document.getElementById('password');
const showPasswordToggle = document.getElementById('showPassword');
showPasswordToggle.addEventListener('click', () => {
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
showPasswordToggle.textContent = 'Sembunyikan Password';
} else {
passwordInput.type = 'password';
showPasswordToggle.textContent = 'Lihat Password';
}
});
});
</script>
<br>
<button type="submit" class="submit" name="login">LOG IN</button>
</form>
</div>
</div>
</div>
<div class="right">
<div class="right-text">
<h2>DATA WAJIB IPEDA</h2>
<h5>DESA ROWOSARI</h5>
</div>
<div class="right-inductor"><img src="https://lh3.googleusercontent.com/fife/ABSRlIoGiXn2r0SBm7bjFHea6iCUOyY0N2SrvhNUT-orJfyGNRSMO2vfqar3R-xs5Z4xbeqYwrEMq2FXKGXm-l_H6QAlwCBk9uceKBfG-FjacfftM0WM_aoUC_oxRSXXYspQE3tCMHGvMBlb2K1NAdU6qWv3VAQAPdCo8VwTgdnyWv08CmeZ8hX_6Ty8FzetXYKnfXb0CTEFQOVF4p3R58LksVUd73FU6564OsrJt918LPEwqIPAPQ4dMgiH73sgLXnDndUDCdLSDHMSirr4uUaqbiWQq-X1SNdkh-3jzjhW4keeNt1TgQHSrzW3maYO3ryueQzYoMEhts8MP8HH5gs2NkCar9cr_guunglU7Zqaede4cLFhsCZWBLVHY4cKHgk8SzfH_0Rn3St2AQen9MaiT38L5QXsaq6zFMuGiT8M2Md50eS0JdRTdlWLJApbgAUqI3zltUXce-MaCrDtp_UiI6x3IR4fEZiCo0XDyoAesFjXZg9cIuSsLTiKkSAGzzledJU3crgSHjAIycQN2PH2_dBIa3ibAJLphqq6zLh0qiQn_dHh83ru2y7MgxRU85ithgjdIk3PgplREbW9_PLv5j9juYc1WXFNW9ML80UlTaC9D2rP3i80zESJJY56faKsA5GVCIFiUtc3EewSM_C0bkJSMiobIWiXFz7pMcadgZlweUdjBcjvaepHBe8wou0ZtDM9TKom0hs_nx_AKy0dnXGNWI1qftTjAg=w1920-h979-ft" alt=""></div>
</div>
</div>
</section>
</body>
</html>
I’ve tried to ask chatgpt and bingchat and use their recommended solution, but it still the same.
2
Answers
this error means carikrowo is not a part of your database. check spelling and see if column exists by that name. this would be the usual advice.
I’ve checked your files you’re not using carikrowo anywhere. maybe there’s an associated file you’ve forgotten where carikrowo column value is used in processing login.
If you are using
then I assume you hashed the password before storing it to the database so you cannot possibly put the plain text password onto the query where clause
as the password will have been passed in from the user as plain text and therefore will not match the hashed password on the database.
You are also mixing the PDO and MYSQLI_ extensions, that you cannot do.
Stick to one or the other. I would suggest PDO, but as most of this code appears to be MYSQLI_ based I will stick with that.
So you will need something like this:
Now you should actually be finding the user to check the password is right