-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
132 lines (127 loc) · 5.24 KB
/
signup.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
require_once "pdo.php";
session_start();
if (isset($_SESSION['uname'])) {
header('Location: index.php');
return;
}
if (isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['uname']) && isset($_POST['email']) && isset($_POST['pass']) && isset($_POST['cpass']) && isset($_POST['date'])) {
if(strlen($_POST['pass']) < 8) {
$_SESSION['sgnerr'] = "Password must be atleast 8 characters long";
header("Location: signup.php");
return;
}
if ($_POST['pass'] != $_POST['cpass']) {
$_SESSION['sgnerr'] = "Passwords should match";
header("Location: signup.php");
return;
}
$sql = "SELECT user_id FROM users WHERE username = :uname";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
":uname" => $_POST['uname']
));
if ($stmt->fetchALL()) {
$_SESSION['sgnerr'] = "Username already exists. Choose a different one";
header("Location: signup.php");
return;
}
if (!strpos($_POST['email'],"@") or !strpos($_POST['email'], ".com")) {
$_SESSION['sgnerr'] = "Enter valid email address";
header("Location: signup.php");
return;
}
$sql = "INSERT INTO users(fname, lname,email,username,dob,password) VALUES (:fname, :lname, :email, :uname, :dob, :pass)";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
":fname" => $_POST['fname'],
":lname" => $_POST['lname'],
":email" => $_POST['email'],
":uname" => $_POST['uname'],
":dob" => date("Y-m-d", strtotime($_POST["date"])),
":pass" => md5($_POST['pass'])
));
$sql = "SELECT user_id FROM users WHERE username = :uname";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
":uname" => $_POST['uname']
));
if ($stmt->fetchALL()) {
$_SESSION['sgn'] = "Successfully registered to Medico. Login to your account";
header("Location: login.php");
return;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign up to Medico</title>
<link rel="stylesheet" href="static/css/style.css">
<link rel="icon" type="image/x-icon" href="static/imgs/favicon.ico">
<style>
body {
background: rgba(142, 116, 255,.1);
justify-content: center;
align-items: center;
display: flex;
min-height: 100vh;
}
</style>
</head>
<body>
<div class="main">
<div class="signin">
<h1 class="sn-h">Signup to Medico</h1>
<?php
if (isset($_SESSION['sgnerr'])) { ?>
<p class="errpass" style="margin-bottom: 35px;">*<?= $_SESSION['sgnerr'] ?></p>
<?php
unset($_SESSION['sgnerr']);
} ?>
<form method="post" action="signup.php" class="signup-form">
<div class="sn-row flexbox flexrow">
<div>
<label for="fname">First Name</label>
<input type="text" placeholder="Enter your first name" name="fname" id="fname" required>
</div>
<div>
<label for="lname">Last Name</label>
<input type="text" placeholder="Enter your last name" name="lname" id="lname" required>
</div>
</div>
<div class="sn-row flexbox flexrow">
<div>
<label for="date">Date of Birth</label>
<input type="date" placeholder="Enter your date of birth" name="date" id="date" required>
</div>
</div>
<div class="sn-row flexbox flexrow">
<div>
<label for="uname">Username</label>
<input type="text" placeholder="Enter a username" name="uname" id="uname" required>
</div>
<div>
<label for="email">Email Address</label>
<input type="email" placeholder="Enter your email" name="email" id="email" required>
</div>
</div>
<div class="sn-row flexbox flexrow">
<div>
<label for="pass">Password</label>
<input type="password" placeholder="Enter your password" name="pass" id="pass" required>
</div>
<div>
<label for="cpass">Confirm Password</label>
<input type="password" placeholder="Re-enter your password" name="cpass" id="cpass" required>
</div>
</div>
<input type="submit" value="Register">
</form>
</div>
</div>
</body>
</html>