-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_data.php
89 lines (68 loc) · 2.6 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
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
88
89
<?php
include_once('inc/header.php');
include_once('conn/connection.php');
if(isset($_POST['submit'])){
$fnUC = ucfirst($_POST['first_name']);
$first_name = mysqli_real_escape_string($conn,$fnUC);
$lastnamecaps = ucfirst($_POST['last_name']);
$last_name = mysqli_real_escape_string($conn,$lastnamecaps);
$email_lower = strtolower($_POST['email']);
$user_email = mysqli_real_escape_string($conn,$email_lower);
if($first_name == "" || $last_name == "" || $user_email == ""){
//echo "all fields req";
//$_SESSION['all_req'] = "All fields are required";
$_SESSION['all_req'] ='<div class="col-md-6"><div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Error!</strong> All fields are required!!!.
</div></div>';
header('location:index.php');
}else if(!preg_match("/^[a-zA-Z ]*$/", $first_name)){
$_SESSION['letters_req']="Only letters are allowed";
header('location:index.php');
}else if(!preg_match("/^[a-zA-Z ]*$/", $last_name)){
$_SESSION['letters_req']="Only letters are allowed";
header('location:index.php');
}else if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)) {
echo"Enter a valid email";
}
else{
$checking_exist_email = "SELECT email FROM users WHERE email = ?";
$fire_query = $conn->prepare($checking_exist_email);
$fire_query->bind_param("s", $user_email);
$fire_query->execute();
$fire_query->bind_result($found);
$fire_query->fetch();
if($found)
{
//echo "Email is already exist";
// $email_exist = "email exist";
// header('location:index.php');
// $_SESSION['email_exist']="Email is already exist";
$_SESSION['email_exist'] ='<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Error!</strong>This email '.$user_email.' is already exist!!!.
</div>';
header('location:index.php');
exit();
}
else{
$insert_data = $conn->prepare("INSERT INTO users(first_name, last_name,email) VALUES (?,?,?)");
$insert_data->bind_param("sss", $first_name, $last_name, $user_email);
if($insert_data->execute()){
//$_SESSION['register_done']="Registration Done!!!";
//echo "New records created successfully";
$_SESSION['register_done'] ='<div class="alert alert-success">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Success!</strong> Registration Done Check your registered email for password !!!.
</div>';
header("location:index.php");
//echo "Insert";
}
else{
echo "Something went wrong";
}
$insert_data->close();
$conn->close();
}
}}
?>