-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup_script.php
49 lines (38 loc) · 1.75 KB
/
signup_script.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
<?php
require("includes/common.php");
// Getting the values from the signup page using $_POST[] and cleaning the data submitted by the user.
$name = $_POST['name'];
$name = mysqli_real_escape_string($con, $name);
$email = $_POST['email'];
$email = mysqli_real_escape_string($con, $email);
$password = $_POST['password'];
$password = mysqli_real_escape_string($con, $password);
$contact = $_POST['contact'];
$contact = mysqli_real_escape_string($con, $contact);
$city = $_POST['city'];
$city = mysqli_real_escape_string($con, $city);
$address = $_POST['address'];
$address = mysqli_real_escape_string($con, $address);
$regex_email = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/";
$regex_num = "/^[789][0-9]{9}$/";
$query = "SELECT * FROM users WHERE email='$email'";
$result = mysqli_query($con, $query)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($regex_email, $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: products.php');
}
?>