mahin993 / country-details

0 stars 0 forks source link

Login Form with PHP #5

Open mahin993 opened 7 months ago

mahin993 commented 7 months ago

<!DOCTYPE html>

Login Page

Login

Register

// login php <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // Get the posted data $username = $_POST["username"]; $password = $_POST["password"];

// Perform login validation (replace with your actual validation logic)
// For demonstration purposes, this example assumes a simple check
if ($username == "demo" && $password == "password") {
    echo "Login successful";
} else {
    echo "Login failed";
}

} else { echo "Invalid request method"; } ?>

// register php

<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // Get the posted data $regUsername = $_POST["regUsername"]; $regPassword = $_POST["regPassword"];

// Perform registration logic (replace with your actual registration logic)
// For demonstration purposes, this example assumes a simple success message
echo "Registration successful";

} else { echo "Invalid request method"; } ?>

//index.php

<!DOCTYPE html>

Employee Management System 0) { while ($row = mysqli_fetch_assoc($result)) { echo "

Employee ID: " . $row['employee_id'] . "

"; echo "

Employee Name: " . $row['employee_name'] . "

"; // Add other employee details as needed } } else { echo "No employee data available."; } // Add a logout button echo '
'; } else { // Display login and registration forms include 'login.php'; include 'register.php'; } ?>

//login php

Login

// register php

Register

//config.php

<?php $servername = "localhost"; $username = "your_username"; $password = "your_password"; $dbname = "your_database_name";

$conn = mysqli_connect($servername, $username, $password, $dbname);

if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } ?>

//login_process.php

<?php session_start();

include 'config.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") { $username = $_POST["username"]; $password = $_POST["password"];

// Perform login validation (replace with your actual validation logic)
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$result = mysqli_query($conn, $query);

if (mysqli_num_rows($result) == 1) {
    $row = mysqli_fetch_assoc($result);
    $_SESSION['user_id'] = $row['user_id'];
    header("Location: index.php");
} else {
    echo "Login failed";
}

} else { echo "Invalid request method"; } ?>

//register_process.php

<?php include 'config.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") { $regUsername = $_POST["regUsername"]; $regPassword = $_POST["regPassword"];

// Perform registration logic (replace with your actual registration logic)
$query = "INSERT INTO users (username, password) VALUES ('$regUsername', '$regPassword')";

if (mysqli_query($conn, $query)) {
    echo "Registration successful";
} else {
    echo "Error: " . mysqli_error($conn);
}

} else { echo "Invalid request method"; } ?>

// logout.php

<?php session_start();

// Destroy the session and redirect to login page session_destroy(); header("Location: index.php"); exit(); ?>

//style.css

body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; display: flex; justify-content: center; align-items: center; height: 100vh; }

.form-container { background-color: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); margin: 10px; }

button { padding: 10px; cursor: pointer; background-color: #4CAF50; color: white; border: none; border-radius: 4px; }

button:hover { background-color: #45a049; }

mahin993 commented 7 months ago

Retrieved data

<!DOCTYPE html>

Employee Management System prepare($query); $stmt->execute(); if ($stmt->rowCount() > 0) { $resultData = $stmt->fetch(PDO::FETCH_ASSOC); // Output data in a modal echo ""; // Button to open the modal echo ""; } else { echo "No employee data available."; } // Add a logout button echo '
'; } else { // Display login and registration forms include 'login.php'; include 'register.php'; } ?>

/ Add your existing styles here /

/ Modal styles / .modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); }

.modal-content { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); }

.close { position: absolute; top: 10px; right: 10px; font-size: 20px; cursor: pointer; }

mahin993 commented 6 months ago

New commt

<!DOCTYPE html>

Dynamic Buttons
connect_error) { die("Connection failed: " . $conn->connect_error); } // Retrieve button properties from POST data $name = $_POST['name']; $shape = $_POST['shape']; $width = $_POST['width']; $height = $_POST['height']; $positionX = $_POST['positionX']; $positionY = $_POST['positionY']; // Insert or update data in the database $query = "INSERT INTO buttons (name, shape, width, height, positionX, positionY) VALUES ('$name', '$shape', $width, $height, $positionX, $positionY) ON DUPLICATE KEY UPDATE width = $width, height = $height, positionX = $positionX, positionY = $positionY"; $result = $conn->query($query); if ($result) { echo "Data saved successfully"; } else { echo "Error: " . $query . "
" . $conn->error; } $conn->close(); } ?>