0% found this document useful (0 votes)
69 views6 pages

Event Registration and Login Script

The document is a PHP script for user registration and login in an event management system, utilizing a MySQL database. It includes HTML and CSS for a user-friendly interface, handling both registration and login functionalities with appropriate success and error messages. Instructions for setting up the environment using XAMPP and creating the necessary database and table are also provided.
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)
69 views6 pages

Event Registration and Login Script

The document is a PHP script for user registration and login in an event management system, utilizing a MySQL database. It includes HTML and CSS for a user-friendly interface, handling both registration and login functionalities with appropriate success and error messages. Instructions for setting up the environment using XAMPP and creating the necessary database and table are also provided.
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
// Database Connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "event_management";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$message = "";
// Handle Registration
if (isset($_POST['register'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "INSERT INTO users (name, email, password) VALUES ('$name', '$email',
'$password')";
if ($conn->query($sql) === TRUE) {
$message = "<div class='success'>Registration successful! <a href='?
action=login'>Login here</a></div>";
} else {
$message = "<div class='error'>Error: " . $conn->error . "</div>";
}
}
// Handle Login
if (isset($_POST['login'])) {
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE email='$email' AND password='$password'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
$message = "<div class='success'>Login successful! Welcome, " .
htmlspecialchars($user['name']) . "</div>";
} else {
$message = "<div class='error'>Invalid email or password.</div>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Auth</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f5f5f5;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
width: 350px;
text-align: center;
}
h1 {
color: #333333;
}
h2 {
color: #444444;
margin-bottom: 20px;
}
.message {
margin: 10px 0;
padding: 10px;
border-radius: 5px;
font-size: 14px;
}
.success {
color: #155724;
background-color: #d4edda;
border: 1px solid #c3e6cb;
}
.error {
color: #721c24;
background-color: #f8d7da;
border: 1px solid #f5c6cb;
}
form {
text-align: left;
}
label {
display: block;
margin-bottom: 5px;
color: #555555;
}
input[type="text"],
input[type="email"],
input[type="password"] {
width: 100%;
padding: 8px;
margin-bottom: 15px;
border: 1px solid #cccccc;
border-radius: 4px;
font-size: 14px;
}
button {
background: #007bff;
color: #ffffff;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background: #0056b3;
}
a{
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
p{
margin-top: 10px;
color: #666666;
}
</style>
</head>
<body>
<div class="container">
<h1>Event Authentication</h1>

<?php
// Display Message
if (!empty($message)) {
echo $message;
}
// Display Registration Form
if (!isset($_GET['action']) || $_GET['action'] === 'register') {
?>
<h2>Register</h2>
<form method="POST">
<label for="name">Name:</label>
<input type="text" name="name" required>
<label for="email">Email:</label>
<input type="email" name="email" required>
<label for="password">Password:</label>
<input type="password" name="password" required>
<button type="submit" name="register">Register</button>
</form>
<p>Already registered? <a href="?action=login">Login here</a></p>
<?php
}
// Display Login Form
if (isset($_GET['action']) && $_GET['action'] === 'login') {
?>
<h2>Login</h2>
<form method="POST">
<label for="email">Email:</label>
<input type="email" name="email" required>
<label for="password">Password:</label>
<input type="password" name="password" required>
<button type="submit" name="login">Login</button>
</form>
<p>Don't have an account? <a href="?action=register">Register here</a></p>
<?php
}
?>
</div>
</body>
</html>
STEPS:
1. Install the XAMPP server, open the XAMPP control panel, and then start Apache and
MySQL.
2. Then go to C:\xampp\htdocs, and create one folder “WEB TECH”, saves the above
code as “[Link]”.
3. Go to the browser and search as [Link] create a database
“event_management” and create a “users” table with 3 columns (name, email and
password).
4. Go to the browser and search as [Link]

You might also like