I’m not sure where to start with learning and applying JS exactly.
I don’t have a clue of how to show a dialogue for invalid password/username.
registry.html
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<link rel="stylesheet" href="Design/style.css">
<title>JS lesson</title>
</head>
<body>
<div class="registry-page">
<form method="post" id="loginform" action="Service/login.php" class="login"><!---->
<h2>Login</h2>
<p id="alert"></p>
<div class="inputbox">
<input type="text" id="loginname" name="name" placeholder="name" minlength="3" autocomplete="off" required><br><br>
</div>
<div class="inputbox">
<input type="text" id="loginpassword" name="password" placeholder="password" minlength="3" autocomplete="off" required><br><br>
</div>
<button type="submit" value="Login">Login</button>
<p class="message"><a href="#">Create account now</a></p>
</form>
<br>
<form method="post" id="signupform" action="Service/signup.php" class="registration"><!---->
<h2>Sign Up</h2>
<div class="inputbox">
<input type="text" id="signupname" name="name" placeholder="name" minlength="3" autocomplete="off" required><br><br>
</div>
<div class="inputbox">
<input type="text" id="signuppassword" name="password" placeholder="password" minlength="3" autocomplete="off" required><br><br>
</div>
<button type="submit" value="Register">Register</button>
<p class="message"><a href="#">Back to Sign In</a></p>
</form>
</div>
<script src="Script/backend.js"></script>
</body>
</html>
login.php
<?php
include 'db.php';
header('Content-Type: application/json');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$password = $_POST['password'];
$stmt = $db->prepare("SELECT * FROM users WHERE name = ?");
$stmt->bind_param("s", $name);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
if ($password === $row['password']) {
$_SESSION['username'] = $row['name'];
header("Location: /Javascript/Project/Interface/menu.html?name=" . urlencode($row['name']));
exit();
} else {
echo "Invalid Password";
}
} else {
echo "Invalid username";
}
$stmt->close();
$db->close();
}
else{
echo json_encode(['success'=>false, 'message'=>"Invalid request"]);
}
?>