- Searching means to find whether a particular value is present in the array or not.
- If the value is present in array then the search is said to be successful and the search process gives the location of that value in array,otherwise,if the value is not present in the array the search process displays the appropriate message and in this case search is said to be unsuccessful.
- There are two popular methods for searching the array elements-:
2- Binary Search CLICK HERE
<!DOCTYPE html>
<html>
<head>
<title>User Login</title>
</head>
<body>
<h1>User Login</h1>
<form method="post" action="login_process.php">
<label for="email">Email:</label>
<input type="email" name="email" required>
<br>
<label for="password">Password:</label>
<input type="password" name="password" required>
<br>
<button type="submit">Login</button>
</form>
</body>
</html>
<?php
// Establish database connection (Replace the placeholders with your database credentials)
$servername = "your_servername";
$username = "your_username";
$password = "your_password";
$dbname = "your_database_name";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Function to safely handle user inputs
function sanitize_input($input)
{
return htmlspecialchars(trim($input));
}
// Handle login form submission
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$email = sanitize_input($_POST["email"]);
$password = $_POST["password"];
// Retrieve the user record based on the provided email
$sql = "SELECT id, password, is_admin FROM users WHERE email = '$email'";
$result = $conn->query($sql);
if ($result->num_rows === 1) {
$row = $result->fetch_assoc();
$hashed_password = $row["password"];
$is_admin = $row["is_admin"];
// Verify the provided password against the hashed password in the database
if (password_verify($password, $hashed_password)) {
echo "Login successful!";
// Now you can set session variables or perform other actions based on the user's role (is_admin)
} else {
echo "Invalid email or password.";
}
} else {
echo "Invalid email or password.";
}
}
$conn->close();
?>
follow tech peogramiz
ReplyDelete