Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
2.1 kB
5
Indexable
Never

<?php
// Database connection details
$servername = "localhost"; // Server name or IP
$username = "root"; // MySQL username
$password = ""; // MySQL password
$dbname = "beststoredb"; // Database name

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// SQL query to fetch all data from users table
$sql = "SELECT first_name, last_name, email, address, password FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    echo "<table border='1'>";
    echo "<tr><th>First Name</th><th>Last Name</th><th>Email</th><th>Address</th><th>Password</th></tr>";
    
    while($row = $result->fetch_assoc()) {
        echo "<tr>
                <td>" . $row["first_name"] . "</td>
                <td>" . $row["last_name"] . "</td>
                <td>" . $row["email"] . "</td>
                <td>" . $row["address"] . "</td>
                <td>" . $row["password"] . "</td>
              </tr>";
    }
    echo "</table>";
} else {
    echo "0 results";
}

// Close connection
$conn->close();
?>





<?php
// Start the session
session_start();

// Connect to the database
$servername = "localhost";
$username = "root"; // Replace with your MySQL username
$password = ""; // Replace with your MySQL password
$dbname = "your_database"; // Replace with your database name

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Get the email from the form
    $email = $_POST['email'];

    // Check if the email is admin's email
    if ($email == "admin@gmail.com") {
        // Redirect to Admin_dashboard.php
        header("Location: Admin_dashboard.php");
        exit();
    } else {
        echo "Access denied. You are not authorized.";
    }
}

// Close the connection
$conn->close();
?>
Leave a Comment