· 6 years ago · Jul 24, 2019, 02:36 AM
1<?php
2 $servername = "localhost";
3 $username = "root";
4 $password = "";
5
6
7 $first_name= $_POST["first_name"];
8 $last_name= $_POST["last_name"];
9 $email=$_POST["email"];
10 $registeredname=$_POST["username"];
11 $registeredpassword=$_POST["password"];
12 $hashed_password=password_hash("$password", PASSWORD_BCRYPT);
13
14
15
16 // Create connection
17 $conn = new mysqli($servername, $username, $password);
18
19
20 //Check if we are connected.
21if($conn->connect_error){
22 die("Connection failed:" . $conn->connect_error);
23} else{
24
25
26 //Create the database
27
28 $sql="CREATE DATABASE IF NOT EXISTS registration";
29 if ($conn->query($sql)===TRUE){
30
31 echo "Database has been successfully created!";
32
33 } else {
34 echo "Error creating database:" .$conn->error;
35 }
36 $conn->close();
37}
38
39$sql2="CREATE TABLE IF NOT EXISTS userdetails (
40`firstName` TEXT NOT NULL ,
41`lastName` TEXT NOT NULL ,
42`email` VARCHAR(100) NOT NULL ,
43`userName` VARCHAR(100) NOT NULL ,
44`hash` VARCHAR(80) NOT NULL ,
45PRIMARY KEY (`userName`),
46UNIQUE (`email`)) ENGINE = InnoDB;";
47
48if ($conn->query($sql2)===TRUE) {
49 echo "Table has been successfully created!";
50}else {
51 echo "Error creating table:" . $conn->error;
52}
53$conn->close();
54
55 $sql3 = "Insert Into userdetails (firstName, lastName, email, userName, hash) Values('$first_name', '$last_name', '$email', '$registeredname','$hashed_password')";
56
57
58
59 if ($conn->query($sql3) === TRUE) {
60 echo "Inserted values successfully!";
61} else {
62 echo "Error: you have entered not entered a unique value! Duplicate value will be specified below." . "<br>" . $conn->error;
63}
64
65
66
67
68 $conn->close();
69?>