Здравствуйте, это система входа в систему, использующая процедурное программирование в php и mysql. Предполагается, что программа проверит, существует ли пользователь, и проверит его данные для входа в систему. Тем не менее, он пропускает все блоки операторов в первом / главном (если оператор), которые предназначены для проверки. Каждый раз выполняется последний (оператор else) в конце программы.
<?php
if (isset($_POST['login-submit'])) {
require 'dbhand.inc.php';
/*store value from user*/
$username = $_POST['uid'];
$password = $_POST['Pwd'];
/*check for empty fields*/
if(empty($username) || empty($password)) {
header ("Location: ../SchlofMin.php?=emptyfields");
exit();
}
//check if user is registered
else{
$sql = "SELECT * FROM yoozas WHERE uidUsers=?";
//initialize a new statment
$stmt = mysql_stmt_init($con);
//check if the above doesn,t work
if (!mysqli_stmt_prepare($stmt, $sql)){
header("Location; ../SchlofMin.php?error=sqlerror");
exit();
}
else{
//bind and pass user info into the database
msqli_stmt_bind_param($stmt, "ss", $username, $username);
//executing the binded statement
msqli_stmt_execute($stmt);
//insertinging the binded statement into a variable
$result = mysqli_stmt_get_result($stmt);
//to check if we actually got a result from the database
if ($row = mysqli_fetch_assoc($result)) {
//if user exists, we will grab his password and check for match with pass in database
$checkPwd = password_verify($password, $row['pwdUsers']);
//check if password is false
if ($checkPwd = false) {
header("Location: ../SchlofMin?error=wrongpwd");
exit();
}
//check if password is true
else if ($checkPwd = true) {
//start a session
session_start();
$_SESSION['userId'] =$row['idUsers'];
$_SESSION['userUid'] =$row['uidUsers'];
//take user back to SchlofMin with a sucess message
header("Location: ../SchlofMin.php?login=success");
}
//incase password is not true or false
else{
header("Location: ../SchlofMin.php?error=wrongpwd");
exit();
}
}
else{
//if we didn't get any result from the database
header("Location: ../SchlofMin.php?error=nouser");
exit();
}
}
}
}
else {
header("Location: ../SchlofMin.php?ERRORRRRR");
exit();
}