-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
284 lines (262 loc) · 5.95 KB
/
Copy pathindex.php
File metadata and controls
284 lines (262 loc) · 5.95 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
session_start();
$_SESSION['email']="";
$_SESSION['password']="";
$_SESSION['uid']="";
$_SESSION['status']=0;
?>
<?php
$msg="";
$user="";
$pass="";
?>
<!DOCTYPE html>
<html>
<head>
<title>Online Editor</title>
<script type="text/javascript" src="script/jquery-3.1.1.min.js"></script>
<link rel="StyleSheet" type="text/css" href="design/sheetIndex.css">
<script type="text/javascript" src="script/scriptIndex.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="page1">
<div class="header">
<div id="headName">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<span id="titleWebsite"><b>Online Editor</b></span>
<span><button id="btnLoginForm">login</button></span>
<span><button id="btnSignupForm">Signup</button></span>
</div>
<div></div>
</div>
<script>
/*for toggling the fodiv
Username 
rm*/
$(document).ready(function(){
$("#btnLoginForm").click(function(){
$("#loginForm").show();
$('#btnSignupForm').show();
$('#btnLoginForm').hide();
$('#signupForm').hide();});
$("#btnSignupForm").click(function(){
$('#signupForm').show();
$('#btnLoginForm').show();
$('#btnSignupForm').hide();
$('#loginForm').hide();});
});
</script>
<div class="forms">
<div id="loginForm">
<form name="login" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" onsubmit="afterLogin()">
<table id="loginTable">
<tr>
<td id="tc"></td>
<td id="tc"></td>
</tr>
<tr>
<td id="tc">Username</td>
<td id="tc"><input type="text" name="username"></td>
</tr>
<tr>
<td id="tc">Password</td>
<td id="tc"><input type="password" name="password"></td>
</tr>
<tr>
<td id="tcerr" style="padding:5px 10px 5px 10px"><?php echo $msg; ?></td>
<td id="tc"><button id="#btnLogin" name="submit" value="1">Login</button></td>
</tr>
</table>
</form>
</div>
<div id="signupForm">
<form name="signup" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> ">
<table id="loginTable">
<tr id="tr1">
<td id="tc"></td>
<td id="tc"></td>
</tr>
<tr>
<td id="tc">FirstName</td>
<td id="tc"><input type="text" name="firstName"></td>
</tr>
<tr>
<td id="tc">LastName</td>
<td id="tc"><input type="text" name="lastName"></td>
</tr>
<tr>
<td id="tc">Email/Username</td>
<td id="tc"><input type="text" name="email"></td>
</tr>
<tr>
<td id="tc">Contact Number</td>
<td id="tc"><input type="text" name="number"></td>
</tr>
<tr>
<td id="tc">Password</td>
<td id="tc"><input type="password" name="password"></td>
</tr>
<tr id="trn">
<td id="tc"><?php echo $msg; ?></td>
<td id="tc"><button id="btnSignup" name="submit" value="2" onclick="">Signup</button></td>
</tr>
</table>
</form>
</div>
</div>
<script>
$('document').ready(function(){
$('button').click(function(){
$('.welcome').hide();
});
});
</script>
<div class="welcome">
<div id="welcome1">
<span>Welcome to Online Editor</span>
<span></span>
<br>
</div>
</div>
<div class="footer">
<p id="test"><?php echo $msg;?></p>
<div id="snackbar">
<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
{
if($_POST['submit']=="1")
{
$user=$_POST['username'];
$pass=$_POST['password'];
if(strlen($user)==0 || strlen($pass)==0)
{
$msg="Please ,complete the form";
echo "<script>loginClick()</script>";
echo $msg;
}
else
{
$msg=login($user,$pass);
echo $msg;
echo "<script>loginClick();</script>";
}
}
else if($_POST['submit']=="2")
{
$fn=$_POST['firstName'];
$ln=$_POST['lastName'];
$user=$_POST['email'];
$num=$_POST['number'];
$pass=$_POST['password'];
if(strlen($fn)==0 || strlen($ln)==0 || strlen($user)==0 || strlen($num)==0 || strlen($pass)==0)
{
$msg="Please ,fill the form correctly";
echo $msg;
echo "<script>signupClick();</script>";
}
else
{
$msg=signup($fn,$ln,$user,$num,$pass);
echo $msg;
echo "<script>signupClick();</script>";
}
}
else if($_POST['submit']=="3")
{
$msg="Thanks for Login";
$_SESSION['status']=0;
$_SESSION['username']="";
$_SESSION['password']="";
$_SESSION['uid']="";
$_SESSION['username']="";
session_destroy();
echo $msg;
echo "<script>loginClick();</script>";
}
}
function login($user,$pass)
{
$conn=new mysqli("localhost:3306","admin","12345678","mydb");
if($conn->connect_error)
{
die("Connection failed :");
return "server not working";
}
$sql="select * from account where email='".$user."';" ;
$result=$conn->query($sql);
if($result->num_rows>0)
{
$p='';
$id='';
while($row =$result->fetch_assoc())
{
$p=$row["passward"];
$id=$row["uid"];
}
if($pass==$p)
{
$_SESSION['email']=$user;
$_SESSION['password']=$pass;
$_SESSION['uid']=$id;
$_SESSION['status']=1;
$sql="select firstName,lastName from profile where id='".$id."';";
$row=null;
$result1=$conn->query($sql);
if($result1->num_rows>0)
{
while($row=$result1->fetch_assoc()){
$fname=$row['firstName'];
$lname=$row['lastName'];
$_SESSION['username']=$fname." ".$lname;}
}
return "login successfull";
}
else
{
return "username or password does not match";
}
}
}
function signup($fn,$ln,$user,$num,$pass)
{
$conn=new mysqli("localhost:3306","alpha","1234","website");
if($conn->connect_error)
{
die("Connection failed :");
return "server not working";
}
$sql="select * from account where email='".$user."';" ;
$result=$conn->query($sql);
if($result->num_rows==0)
{
$sql1="insert into profile (firstName,lastName,phone,email) values('".$fn."','".$ln."','".$num."','".$user."');";
$sql2="select id from profile where email='".$user."';";
$conn->query($sql1);
$result1=$conn->query($sql2);
$id=0;
if($result1->num_rows>0)
{
while($row =$result1->fetch_assoc())
{
$id=$row["id"];
}
}
$sql3="insert into account(uid,email,passward) values(".$id.",'".$user."','".$pass."');";
$conn->query($sql3);
return "Login Successfull";
}
}
?>
</div>
</div>
</div>
<?php
if($_SESSION['status']==1)
{
echo "<script>afterLogin();</script>";
include "database.php";
}
?>
</body>
</html>