-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinsert-data.php
29 lines (27 loc) · 1.03 KB
/
insert-data.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
<?php
function insertData($conn, $u_name, $u_email)
{
$u_name = trim(mysqli_real_escape_string($conn, htmlspecialchars($u_name)));
$u_email = trim(mysqli_real_escape_string($conn, htmlspecialchars($u_email)));
// IF NAME OR EMAIL IS EMPTY
if (empty($u_name) || empty($u_email)) {
return 'Please fill all required fields.';
}
//IF EMAIL IS NOT VALID
elseif (!filter_var($u_email, FILTER_VALIDATE_EMAIL)) {
return 'Invalid email address.';
} else {
$check_email = mysqli_query($conn, "SELECT `email` FROM `users` WHERE `email` = '$u_email'");
// IF THE EMAIL IS ALREADY IN USE
if (mysqli_num_rows($check_email) > 0) {
return 'This email is already registered. Please try another.';
}
// INSERTING THE USER DATA
$query = mysqli_query($conn, "INSERT INTO `users`(`name`,`email`) VALUES('$u_name','$u_email')");
// IF USER INSERTED
if ($query) {
return true;
}
return 'Opps something is going wrong!';
}
}