-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
157 lines (143 loc) · 5.08 KB
/
register.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
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
<?php
include('connection.php');
//print_r($_POST);
$change_mode='save';
if(isset($_POST)){
if(isset($_POST['mode']) && $_POST['mode']=='save'){
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$username=$_POST['username'];
$Cpassword=$_POST['Cpassword'];
$password=$_POST['password'];
$sql="INSERT INTO register_db SET first_name='$first_name', last_name='$last_name', username='$username',Cpassword = '$Cpassword', password='$password'";
if (mysqli_query($conn, $sql)) {
header('Location:data.php');
}else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
}
if(isset($_POST)){
if(isset($_POST['mode']) && $_POST['mode']=='update'){
//print_r($_POST);
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$username=$_POST['username'];
$update_key=$_POST['update_key'];
$sql="UPDATE register_db SET first_name='$first_name', last_name='$last_name', username='$username',Cpassword = '$Cpassword', password='$password' WHERE id='$update_key'";
if (mysqli_query($conn, $sql)) {
header('Location:data.php');
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
}
if(isset($_GET)){
if(isset($_GET['mode']) && $_GET['mode']=='edit'){
$user_id=$_GET['user_id'];
$sql = "SELECT * FROM register_db where id='$user_id'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
$first_name=$row['first_name'];
$last_name=$row['last_name'];
$username=$row['username'];
}
}
$change_mode='update';
}
}
mysqli_close($conn)
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 4</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="js/bootstrap.js"></script>
<script>
function submitForm(){
var d=document.register_form;
var password=d.password.value;
var confirm_password=d.Cpassword.value;
if(password!=confirm_password){
$('#Cpassword_msg').html('password not match');
return false;
}
d.action='';
d.submit();
}
function checkPassword(){
var d=document.register_form;
var password=d.password.value;
var confirm_password=d.Cpassword.value;
if(password!=confirm_password){
$('#Cpassword_msg').html('password not match');
return false;
}else{
$('#Cpassword_msg').html('password ok');
}
}
// function checkActivity() {
// alert("Input field lost focus.");
// }
function emptyActivity(){
var d=document.register_form;
var first_name=d.first_name.value;
var username=d.username.value;
var password=d.password.value;
if(first_name == '' || username == '' || password == ''){
alert("Fill the required field");
return false;
}else{
d.action='';
d.submit();
}
}
</script>
</head>
<body>
<?php
include('header_menu.php');
?>
<div class="container">
<div class="row">
<form name="register_form" action="register.php" method="post" onSubmit="return false;">value ="<?php echo (isset($first_name))?$first_name:'';?>"
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" class="form-control" id="first_name" placeholder="Enter your First Name" name="first_name" value ="<?php echo (isset($first_name))?$first_name:'';?>">
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" class="form-control" id="last_name" placeholder="Enter your Last Name" name="last_name" value ="<?php echo (isset($last_name))?$last_name:'';?>">
</div>
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" id="username" placeholder="Enter Username" name="username" value ="<?php echo (isset($username))?$username:'';?>">
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" class="form-control" id="password" placeholder="Enter password" name="password">
</div>
<div class="form-group">
<label for="Cpassword">Confirm Password:</label>
<input type="password" class="form-control" id="Cpassword" placeholder="Enter Confirm password" name="Cpassword" onKeyUp="checkPassword()">
<span class="text-danger" id="Cpassword_msg"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="remember"> Remember me
</label>
</div>
<input type="hidden" name="update_key" value="<?php echo $user_id;?>">
<input type="hidden" name="mode" value="<?php echo $change_mode;?>">
<button type="register" class="btn btn-primary" onclick="emptyActivity()">Register</button>
</form>
</div>
</div>
</body>
</html>