-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
75 lines (61 loc) · 2.02 KB
/
functions.php
File metadata and controls
75 lines (61 loc) · 2.02 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
<?php
function emptyInputSignUp($username,$password,$email,$age,$gender,$message){
$result;
if(empty($username) || empty($password) || empty($email) || empty($age) || empty($gender) || empty($message)){
$result = true;
}
else{
$result = false;
}
return $result;
}
function invalidUsername($username){
$result;
if(!preg_match("/^[a-zA-Z0-9]*$/",$username)){
$result = true;
}
else{
$result = false;
}
return $result;
}
function invalidEmail($email) {
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$result = true;
}
else{
$result = false;
}
return $result;
}
function usernameExists($conn, $username,$email) {
$sql = "SELECT * FROM users WHERE ID = ? OR email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt,$sql)){
header("Location: ./user page.php?error=stmtfailed");
exit();
}
mysqli_stmt_bind_param($stmt,'ss',$username.$email);
mysqli_stmt_execute($stmt);
$resultdata= mysqli_stmt_get_result($stmt);
if($row = mysqli_fetch_assoc($resultdata)){
return $row;
}else{
$result = false;
return $result;
}
mysqli_stmt_close($stmt);
}
function createUser($conn,$username,$password,$email,$age,$gender,$message) {
$sql = "INSERT INTO `users`(`username`, `password`, `email`, `age`, `gender`, `message`) VALUES (?, ?. ?, ?, ?, ?); ";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt,$sql)){
header("Location: ./user page.php?error=stmtfailed");
exit();
}
$hashedpass = password_hash($password,PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt,'ssssss',$username,$hashedpass,$email,$age,$gender,$message);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
header("Location: ./user page.php?error=none");
}