-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup-check.php
73 lines (59 loc) · 1.91 KB
/
signup-check.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
<?php
session_start();
include "db_conn.php";
if (isset($_POST['uname']) && isset($_POST['password'])
&& isset($_POST['name']) && isset($_POST['re_password'])) {
function validate($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$uname = validate($_POST['uname']);
$pass = validate($_POST['password']);
$re_pass = validate($_POST['re_password']);
$name = validate($_POST['name']);
$user_data = 'uname='. $uname. '&name='. $name;
if (empty($uname)) {
header("Location: signup.php?error=User Name is required&$user_data");
exit();
}else if(empty($pass)){
header("Location: signup.php?error=Password is required&$user_data");
exit();
}
else if(empty($re_pass)){
header("Location: signup.php?error=Retype Password is required&$user_data");
exit();
}
else if(empty($name)){
header("Location: signup.php?error=Name is required&$user_data");
exit();
}
else if($pass !== $re_pass){
header("Location: signup.php?error=The confirmation password does not match&$user_data");
exit();
}
else{
// hashing the password
// $pass = md5($pass);
$sql = "SELECT * FROM article WHERE user_name='$uname' ";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
header("Location: signup.php?error=The username is taken try another&$user_data");
exit();
}else {
$sql2 = "INSERT INTO article(user_name, password, name) VALUES('$uname', '$pass', '$name')";
$result2 = mysqli_query($conn, $sql2);
if ($result2) {
header("Location: signup.php?success=Your account has been created successfully");
exit();
}else {
header("Location: signup.php?error=unknown error occurred&$user_data");
exit();
}
}
}
}else{
header("Location: signup.php");
exit();
}