-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
59 lines (49 loc) · 1.26 KB
/
register.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
<?php
$name = $_POST['name']; //posting to server
$email = $_POST['email'];
$password = $_POST['password'];
if (!empty($name) || !empty($email) || !empty($password)) //Checking empty fields
{
$host = "localhost";
$dbUsername="root";
$dbPassword="";
$dbname="webshelf";
//creating connection
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
if (mysqli_connect_error())
{
die('Connection error('. mysqli_connect_errno(). ')'. mysqli_connect_error());
}
else
{
$SELECT = "SELECT email From register Where email=? Limit 1";
$INSERT = "INSERT Into register (name, email, password) values(?,?,?)";
//Prepare statement
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($email);
$stmt->store_result();
$rnum = $stmt->num_rows;
if ($rnum==0)
{
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("sss", $name, $email, $password);
$stmt->execute();
echo "You have been successfully registered";
}
else
{
echo "Sorry, this email is already registered :(";
}
$stmt->close();
$conn->close();
}
}
else
{
echo "All fields are required"; //error display
die();
}
?>