-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_registration_script.php
49 lines (48 loc) · 2.05 KB
/
user_registration_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 'connection.php';
session_start();
$name= mysqli_real_escape_string($con,$_POST['name']);
$email=mysqli_real_escape_string($con,$_POST['email']);
$regex_email="/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[_a-z0-9-]+)*(\.[a-z]{2,3})$/";
if(!preg_match($regex_email,$email)){
echo "Incorrect email. Redirecting you back to registration page...";
?>
<meta http-equiv="refresh" content="2;url=signup.php" />
<?php
}
$password=md5(md5(mysqli_real_escape_string($con,$_POST['password'])));
if(strlen($password)<6){
echo "Password should have atleast 6 characters. Redirecting you back to registration page...";
?>
<meta http-equiv="refresh" content="2;url=signup.php" />
<?php
}
$contact=$_POST['contact'];
$city=mysqli_real_escape_string($con,$_POST['city']);
$address=mysqli_real_escape_string($con,$_POST['address']);
$duplicate_user_query="select id from users where email='$email'";
$duplicate_user_result=mysqli_query($con,$duplicate_user_query) or die(mysqli_error($con));
$rows_fetched=mysqli_num_rows($duplicate_user_result);
if($rows_fetched>0){
//duplicate registration
//header('location: signup.php');
?>
<script>
window.alert("Email already exists in our database!");
</script>
<meta http-equiv="refresh" content="1;url=signup.php" />
<?php
}else{
$user_registration_query="insert into users(name,email,password,contact,city,address) values ('$name','$email','$password','$contact','$city','$address')";
//die($user_registration_query);
$user_registration_result=mysqli_query($con,$user_registration_query) or die(mysqli_error($con));
echo "User successfully registered";
$_SESSION['email']=$email;
//The mysqli_insert_id() function returns the id (generated with AUTO_INCREMENT) used in the last query.
$_SESSION['id']=mysqli_insert_id($con);
//header('location: products.php'); //for redirecting
?>
<meta http-equiv="refresh" content="3;url=products.php" />
<?php
}
?>