I typed the correct user and the wrong user. I get this message:
Notice: Undefined index: username and Undefined index: password.
I'm getting invalid user input error in the input code.
Line 18 and 23 are returning the Undefined index message.
Incorrect user input is written instead of input in input section.
How to fix this problem? I have examined many topics.
This PHP Code
<?php
session_start();
require_once "../../config.php";
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
header("location: ../../index.php");
exit;
}
$username = " ";
$password = " ";
$username_err = " ";
$password_err = " ";
if($_SERVER["REQUEST_METHOD"]=="POST"){
if(empty(trim($_POST["username"]))){
$username_err = "Lütfen kullanıcı adınızı giriniz.";
} else {
$username = trim($_POST["username"]);
}
if(empty(trim($_POST["password"]))){
$password_err = "Lütfen şifrenizi giriniz.";
} else{
$password = trim($_POST["password"]);
}
if(empty($username_err) && empty($password_err)){
$tsql = "SELECT id, username, password FROM [ARAC_TAKIP].[dbo].[KULLANİCİLAR]
WHERE username = :username ";
if($stmt = $pdo->prepare($tsql)){
$stmt->bindParam(":username", $param_username, PDO::PARAM_STR);
$param_username = trim($_POST["username"]);
if($stmt->execute()){
if($stmt->rowCount() == 1){
if($row = $stmt->fetch()){
$id = $row["id"];
$username = $row["username"];
$hashed_password = $row["password"];
if(password_verify($password, $hashed_password)){
session_start();
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
header("location: ../../index.php");
} else{
$password_err = "Hatalı şifre girdiniz !!";
}
}
} else{$username_err = "Kullanıcı adı bulunamadı.!!";
}
} else{
echo "Oops! Hata oluştu. Yeniden giriş yapınız.";
}
unset($stmt);
}
}
unset($pdo);
}
?>