-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.php
64 lines (39 loc) · 1.5 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
<?php
use function PHPSTORM_META\type;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$username = filter_var($_POST['username'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$password = filter_var($_POST['password'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if ($username != FALSE && $password != FALSE){
$conn = mysqli_connect('127.0.0.1','root','','mydata');
if ($conn != false){
$result = mysqli_query($conn, 'SELECT * FROM userdb');
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$exist = false;
foreach($rows as $row){
if ($username == $row['users']){
$exist = true;
};
};
if ($exist == true){
echo'user name is already exist';
mysqli_close($conn);
header("Refresh: 3; URL=registration.html");
exit;
}else{
$insertsql = "INSERT INTO userdb (users, password) VALUES ('$username', '$password')";
mysqli_query($conn, $insertsql);
mysqli_close($conn);
header("Location: login.html");
}
}else {
echo 'server error ----->>>> '. $conn ;
}
}else {
// Invalid input, handle error
header("Location: registration.html");
exit;
}
}else{
header("Location: registration.html");
exit;
}