-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
63 lines (59 loc) · 2.37 KB
/
server.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
<?php
session_start();
//declaration
$email = "";
$username = "";
$contact = "";
$regno = "";
$password = "";
$cpassword = "";
$errors = array();
//connect to database
$con = mysqli_connect('localhost', 'root', '', 'userform');
//if user clicks register button
if(isset($_POST['register'])){
$name = mysqli_real_escape_string($con, $_POST['name']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$conatct = mysqli_real_escape_string($con, $_POST['contact']);
$regno = mysqli_real_escape_string($con, $_POST['regno']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$cpassword = mysqli_real_escape_string($con, $_POST['cpassword']);
if($password !== $cpassword){
$errors['password'] = "Confirm password not matched!";
}
$email_check = "SELECT * FROM members WHERE email = '$email'";
$res = mysqli_query($con, $email_check);
if(mysqli_num_rows($res) > 0){
$errors['email'] = "The Email that you entered already exists!";
}
/*if($name && $email && $phone && $regno && $password && $cpassword = ""){
$errors['register'] = "Please fill in your details properly!";
}*/
if(count($errors) === 0){
$encpass = password_hash($password, PASSWORD_BCRYPT);
$insert_data = "INSERT INTO memberd (Username, Email, contactno, Registration_no, Password)
values('$username', '$email', '$contact', '$regno')";
$data_check = mysqli_query($con, $insert_data);
}else{
$errors['db-error'] = "Failed while inserting data into database!";
}
}
//if user click login button
if(isset($_POST['login'])){
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$check_email = "SELECT * FROM members WHERE email = '$email'";
$res = mysqli_query($con, $check_email);
if($email && $password == ""){
$errors['email'] = "Email and Password can't be empty";
}
if(mysqli_num_rows($res) > 0){
$fetch = mysqli_fetch_assoc($res);
$fetch_pass = $fetch['password'];
}else{
$errors['email'] = "Incorrect email or password!";
}
}else{
$errors['email'] = "It looks like you're not yet a member! Click on the bottom link to register.";
}
?>