-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.php
83 lines (62 loc) · 2.22 KB
/
registration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html>
<head>
<title>GiftList - Registration</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<?php
//Creating a new account
session_start();
$sessionusername = $_SESSION['username'];
header("location:profile.php?username=$sessionusername");
$con = mysqli_connect('localhost','root','2005eren07');
mysqli_select_db($con, 'giftlist');
$registername = $_POST['registername'];
$registerusername = $_POST['registerusername'];
$registeremail = $_POST['registeremail'];
$registerpassword = $_POST['registerpassword'];
$registerbirthday = $_POST['registerbirthday'];
$s = "SELECT * FROM users WHERE username = '$registerusername'";
$result = mysqli_query($con, $s);
$num = mysqli_num_rows($result);
if($num == 1) {
echo "Username is already taken!";
} else {
$reg = "INSERT INTO users (name, username, email, password, birthday)
VALUES ('$registername','$registerusername','$registeremail','$registerpassword', '$registerbirthday')";
mysqli_query($con, $reg);
echo "Registration successful!";
$_SESSION['username'] = $registerusername;
}
?>
<?php
/*
//Logging a user in
session_start();
if (isset($_POST['login'])) {
$loginusername = $_POST['loginusername'];
$loginpassword = $_POST['loginpassword'];
$conn = new PDO("mysql:host=localhost;dbname=expressview", "root", "2005eren07");
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $conn->prepare("SELECT * FROM users WHERE user_username=:loginusername");
$query->bindParam("user_username", $loginusername, PDO::PARAM_STR);
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);
if (!$result) {
echo '<p class="error">Username password combination is wrong!</p>';
} else {
if (password_verify($loginpassword, $result['user_password'])) {
$_SESSION['user_id'] = $result['user_id'];
echo '<p class="success">Congratulations, you are logged in!</p>';
} else {
echo '<p class="error">Username password combination is wrong!</p>';
}
}
}
*/
?>
</body>
</html>