-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0020504
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
$servername = "localhost"; | ||
$username = "root"; | ||
$password = ""; | ||
$dbname = "final task 2"; | ||
|
||
// Create connection | ||
$conn = new mysqli($servername, $username, $password, $dbname); | ||
|
||
// Check connection | ||
if ($conn->connect_error) { | ||
die("Connection failed: " . $conn->connect_error); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Home</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<h1>Welcome to Our Website</h1> | ||
<button> <a href="login.php">Login</a></button> | <button><a href="signup.php">Signup</a></button> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
include 'db.php'; | ||
if($_SERVER['REQUEST_METHOD']=="POST") | ||
{ | ||
$email = $_POST['email']; | ||
$password = $_POST['password']; | ||
|
||
$sql = "SELECT * FROM users WHERE email='$email'"; | ||
$result = $conn->query($sql); | ||
|
||
if ($result->num_rows > 0) { | ||
$row = $result->fetch_assoc(); | ||
if (password_verify($password, $row['password'])) { | ||
echo "Login successful. Welcome " . $row['name']; | ||
} else { | ||
echo "Invalid password. <a href='login.PHP'>Try again</a>"; | ||
} | ||
} else { | ||
echo "No user found with this email. <a href='signup.PHP'>Signup here</a>"; | ||
} | ||
|
||
$conn->close(); | ||
} | ||
|
||
?> | ||
|
||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Login</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<h2>Login</h2> | ||
<form action="login.php" method="POST"> | ||
<label for="email">Email:</label> | ||
<input type="email" id="email" name="email" required> | ||
<label for="password">Password:</label> | ||
<input type="password" id="password" name="password" required> | ||
<button type="submit">Login</button> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
include 'db.php'; | ||
if($_SERVER['REQUEST_METHOD']=="POST") | ||
{ | ||
// Collect form data | ||
$name = htmlspecialchars(trim($_POST['user_name'])); | ||
$email = htmlspecialchars(trim($_POST['email'])); | ||
$password = htmlspecialchars(trim($_POST['password'])); | ||
|
||
// Hash the password | ||
$hashed_password = password_hash($password, PASSWORD_BCRYPT); | ||
|
||
// Prepare the SQL statement to prevent SQL injection | ||
$stmt = $conn->prepare("INSERT INTO users (user_name, email, password) VALUES (?, ?, ?)"); | ||
$stmt->bind_param("sss", $name, $email, $hashed_password); | ||
|
||
if ($stmt->execute()) { | ||
echo "Signup successful. <a href='login.php'>Login here</a>"; | ||
echo "<script type='text/javascript'> alert('successfully Register')</script>"; | ||
} | ||
else { | ||
echo "Error: " . $stmt->error; | ||
echo "<script type='text/javascript'> alert('enter valid info')</script>"; | ||
} | ||
|
||
$stmt->close(); | ||
$conn->close(); | ||
} | ||
?> | ||
|
||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Signup</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<h2>Signup</h2> | ||
<form action="signup.php" method="POST"> | ||
<label for="name">Name:</label> | ||
<input type="text" id="name" name="user_name" required> | ||
<label for="email">Email:</label> | ||
<input type="email" id="email" name="email" required> | ||
<label for="password">Password:</label> | ||
<input type="password" id="password" name="password" required> | ||
<button type="submit">Signup</button> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
body { | ||
align-items: center; | ||
|
||
font-family: Arial, sans-serif; | ||
background-color: #f0f0f0; | ||
text-align: center; | ||
padding: 20px; | ||
} | ||
|
||
form { | ||
background: #fff; | ||
padding: 20px; | ||
border-radius: 5px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
display: inline-block; | ||
margin-top: 20px; | ||
} | ||
|
||
label { | ||
display: block; | ||
margin-bottom: 8px; | ||
font-weight: bold; | ||
} | ||
|
||
input { | ||
width: 95%; | ||
padding: 8px; | ||
margin-bottom: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
background: #007BFF; | ||
border: none; | ||
color: white; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background: #0056b3; | ||
} |