0% found this document useful (0 votes)
9 views2 pages

New Text Document

This document is a PHP script for an admin login system that connects to a MySQL database to authenticate users. It checks the submitted username and password against the database and sets session variables for successful logins or error messages for failures. The HTML portion provides a login form and displays any error messages related to the login attempt.

Uploaded by

Rahma Azzabi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

New Text Document

This document is a PHP script for an admin login system that connects to a MySQL database to authenticate users. It checks the submitted username and password against the database and sets session variables for successful logins or error messages for failures. The HTML portion provides a login form and displays any error messages related to the login attempt.

Uploaded by

Rahma Azzabi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

<?

php
session_start();

$us = $_POST['username'] ?? '';


$pass = $_POST['pass'] ?? '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {


$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "crud_operation";
$conn = new mysqli($host, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("SELECT username, pass FROM adminn WHERE username = ?");
$stmt->bind_param("s", $us);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
if ($row['pass'] === $pass) {
$_SESSION['username'] = $row['username'];
header("Location: /test/crud/index.php");
exit;
} else {
$_SESSION['error'] = "Mot de passe incorrect!";
}
} else {
$_SESSION['error'] = "Utilisateur non trouvé!";
}
$stmt->close();
$conn->close();

header("Location: admin.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<?php if (isset($_SESSION['error'])): ?>
<div class="alert alert-failure">
<?= htmlspecialchars($_SESSION['error']); ?>
</div>
<?php unset($_SESSION['error']); ?>
<?php endif; ?>
<div class="login-container">
<h2>Admin Login</h2>
<form method="post" action="admin.php">
<input type="text" name="username" placeholder="Your Login *" required>
<input type="password" name="pass" placeholder="Your Password *"
required>
<input type="submit" value="Login">
</form>
<a href="#">Forget Password?</a>
</div>
<footer>
&copy; Copyright 2023 All rights reserved. made by sofyen nefzi
</footer>
</body>
</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy