-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup_script.php
More file actions
38 lines (31 loc) · 1.66 KB
/
signup_script.php
File metadata and controls
38 lines (31 loc) · 1.66 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
<?php
require("includes/common.php");
// Getting the values from the signup page using $_POST[] and cleaning the data submitted by the user.
$name= mysqli_escape_string($con,filter_input(INPUT_POST, 'name'));
$email= mysqli_escape_string($con,filter_input(INPUT_POST, 'email'));
$password= MD5(mysqli_escape_string($con,filter_input(INPUT_POST, 'password')));
$contact= mysqli_escape_string($con,filter_input(INPUT_POST, 'contact'));
$city= mysqli_escape_string($con,filter_input(INPUT_POST, 'city'));
$address= mysqli_escape_string($con,filter_input(INPUT_POST, 'address'));
$regex_num = "/^[789][0-9]{9}$/";
$query1 = "SELECT * FROM users WHERE email='" . $email . "'";
$result = mysqli_query($con, $query1)or die($mysqli_error($con));
$num = mysqli_num_rows($result);
if ($num != 0) {
$m = "<span class='red'>Email Already Exists</span>";
header('location: signup.php?m1=' . $m);
}else if(!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^",$email)) {
$m = "<span class='red'>Not a valid Email Id</span>";
header('location: signup.php?m1=' . $m);
} else if (!preg_match($regex_num, $contact)) {
$m = "<span class='red'>Not a valid phone number</span>";
header('location: signup.php?m2=' . $m);
} else {
$query = "INSERT INTO users(name, email, password, contact, city, address)VALUES('" . $name . "','" . $email . "','" . $password . "','" . $contact . "','" . $city . "','" . $address . "')";
mysqli_query($con, $query) or die(mysqli_error($con));
$user_id = mysqli_insert_id($con);
$_SESSION['email'] = $email;
$_SESSION['user_id'] = $user_id;
header('location: homepage.php');
}
?>