-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertdb.php
More file actions
92 lines (56 loc) · 1.91 KB
/
insertdb.php
File metadata and controls
92 lines (56 loc) · 1.91 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
application/x-httpd-php db_calls.php ( PHP script text )
<?php
// Login
function login(){
$conn = $GLOBALS['conn'];
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
//echo $GLOBALS['conn']; exit;
$sql = "SELECT * FROM users WHERE email='$email' AND password='$password'";
$result = mysqli_query($conn, $sql); //echo 'aaa '.mysqli_num_rows($result);
if (mysqli_num_rows($result) > 0){
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
// return db data
RETURN $row;
}
}
else{ return 'No'; }
mysqli_close($conn);
}
// Insert into Database
function insert_db(){
$conn = $GLOBALS['conn'];
//echo $GLOBALS['conn'];
// Collect value of input field
$firstName = $_REQUEST['firstName'];
$lastName = $_REQUEST['lastName'];
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$sql = "INSERT INTO users (email, password, firstname, lastname)
VALUES ('$email', '$password', '$firstName', '$lastName' )";
if (mysqli_query($conn, $sql)) {
//Send admin confirmation mail
admin_confirmation_mail($email, $firstName);
return 'Yes';
}
else { return 'No'; }
mysqli_close($conn);
}
// Admin updates user status
function changeUserStatus($email, $admin_decision){
$conn = $GLOBALS['conn'];
$sql = "UPDATE users SET status = '$admin_decision' WHERE email = '$email' ";
if (mysqli_query($conn, $sql)) {
RETURN "Your user account is $admin_decision";
} else {
RETURN "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
// Send mail to client
$message = '<h2>Hi,\nYour account has now been activated </h2> You can now login';
// Send mail to User on account status change
$to = $email;
$headers = "From: webmaster@example.com";
mail($to, "Admin Decision on your Account", $message, $headers);
}