-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathregpage.php
More file actions
163 lines (146 loc) · 5.83 KB
/
regpage.php
File metadata and controls
163 lines (146 loc) · 5.83 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrapValidator.css"/>
<link href="assets/bootstrap/css/addpage.css" rel="stylesheet">
<script type="text/javascript" src="assets/jquery/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="assets/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/bootstrap/js/bootstrapValidator.js"></script>
</head>
<body>
<!-------PHP connect------->
<?php
$dbconn = pg_connect("host=localhost port=5432 dbname=postgres user=postgres password=postgres")
or die('Could not connect: ' . pg_last_error());
?>
<!-------Register Form------->
<div class="container" style="margin-top: 50px;">
<div class="row">
<div class="col-lg-4 col-lg-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Sign up</h3>
</div>
<div class="panel-body">
<form id="regForm" method="post">
<div class="form-group">
<input type="text" class="form-control" name="user_name" placeholder="Name" />
</div>
<div class="form-group">
<input type="text" class="form-control" name="user_email" placeholder="Email" />
</div>
<div class="form-group">
<textarea class="form-control" name="user_address" rows="3" placeholder="Your Address"></textarea>
</div>
<div class="form-group">
<input type="password" class="form-control" name="user_pass" placeholder="Password" />
</div>
<div class="form-group">
<input type="password" class="form-control" name="confirmPass" placeholder="Retype password" />
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" name="formSubmit">Sign up</button>
<input type="button" class="btn btn-primary" onclick="location.href='index.php';" value="Back" />
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#regForm').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
user_name: {
message: 'The name is not valid',
validators: {
notEmpty: {
message: 'The name is required and can\'t be empty'
},
regexp: {
regexp: /^[a-zA-Z\s]*$/,
message: 'The name can only consist of alphabetical letters'
}
}
},
user_email: {
validators: {
notEmpty: {
message: 'The email is required and can\'t be empty'
},
emailAddress: {
message: 'The input is not a valid email address'
}
}
},
user_address: {
message: 'The address is not valid',
validators: {
notEmpty: {
message: 'The address is required and can\'t be empty'
},
regexp: {
regexp: /^[a-zA-Z0-9]/,
message: 'The address can only consist of alphabetical letters'
}
}
},
user_pass: {
validators: {
notEmpty: {
message: 'The password is required and can\'t be empty'
},
identical: {
field: 'confirmPassword',
message: 'The password and its confirm are not the same'
}
}
},
confirmPass: {
validators: {
notEmpty: {
message: 'The confirm password is required and can\'t be empty'
},
identical: {
field: 'user_pass',
message: 'The password and its confirm are not the same'
}
}
}
}
});
});
</script>
<?php
if (isset($_POST['formSubmit'])){
$user_email = $_REQUEST['user_email'];
$user_pass = $_REQUEST['user_pass'];
$user_name = $_REQUEST['user_name'];
$user_address = $_REQUEST['user_address'];
$query = "INSERT INTO account (email, name, address, password) VALUES('$user_email', '$user_name', '$user_address ', '$user_pass')";
$result = pg_query($dbconn, $query);
if($result){
echo '<div class="alert alert-success">
Account successfully created!
</div>';
exit;
} else {
echo '<div class="alert alert-danger">
There is already an account registered to this account.
</div>';
}
}
?>
</body>
</html>