0% found this document useful (0 votes)
4 views3 pages

$username $password: $ - Server $ - POST $ - POST

This PHP script handles user login by connecting to a MySQL database to verify credentials. It checks if the username exists and if the provided password matches the stored password. If successful, it starts a session and redirects the user to a dashboard; otherwise, it displays an error message for invalid credentials.

Uploaded by

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

$username $password: $ - Server $ - POST $ - POST

This PHP script handles user login by connecting to a MySQL database to verify credentials. It checks if the username exists and if the provided password matches the stored password. If successful, it starts a session and redirects the user to a dashboard; otherwise, it displays an error message for invalid credentials.

Uploaded by

borgol1914
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

<?

php
session_start();

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

// Connect to your MySQL database


$host = "[Link]";
$db_username = "if0_34849447";
$db_password = "------------";
$db_name = "if0_34849447_umbrella_corp";

$conn = new mysqli($host, $db_username, $db_password, $db_name);

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

// Fetch user from the database


$query = "SELECT * FROM users WHERE username = '$username'";
$result = $conn->query($query);

if ($result->num_rows == 1)
{
$user = $result->fetch_assoc();
echo "Fetched password from database: " . $user["passwordz"] .
"<br>";
//echo "Input password: " . $password . "<br>";
echo "Fetched password from database: " . $user["namez"] . "<br>";
echo "Fetched password from database: " . $user["idz"] . "<br>";
// echo "Fetched password from database: " . $user["sec"] .
"<br>";

$name= $user["namez"];
$userid= $user["idz"];
// $usersec= $user["sec"];
// Verify the password
if ($user["password"]==$_POST["password"])
{
// Password is correct, set up a session and redirect to the
dashboard
$_SESSION["namez"] = $name;
$_SESSION["idz"] = $userid;
// $_SESSION["sec"] = $usersec;
header("Location: [Link]"); // NAME SA INYONG MAIN PAGE
exit();
}
else
{
$error_message = "Invalid password.";

}
} else {
$error_message = "Invalid username.";
}

$conn->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Result</title>
<link rel="stylesheet" type="text/css" href="[Link]">
</head>
<body>
<div class="login-container">
<h2>Login Result</h2>
<?php if (isset($error_message)) { ?>
<p style="color: red;"><?php echo $error_message; ?></p>
<?php } ?>
<p><a href="[Link]">Back to Login</a></p>
</div>
</body>
</html>

You might also like