-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
1 lines (1 loc) · 2.08 KB
/
signup.php
1
<?php session_start(); /* -- SQL Config -- */ $servername = "localhost"; $username = "root"; $password = "root123"; $dbname = "cs634dmadmin"; $_SESSION['logged'] = FALSE; /* -- Create Authorization Here -- */ /* Create sql connection */ $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { echo "Signup Unsucessful!! Cannot connect to MySQL. Please do proper setup of XAAMP again.<br/>Redirecting to Home page in 5 seconds."; header("refresh: 5;url=./index.php"); }else{ /* Creating `User_DB` (or Transaction_DB) with a `Transactions` table within the `User_DB` */ $sql = "INSERT INTO user_credentials VALUES ('".$_POST['su_username']."', '".$_POST['su_password']."')"; if ($conn->query($sql) === TRUE) { echo "Success: In creating the User. <br/>"; $sql = "CREATE DATABASE cs634DM_".$_POST['su_username']."_DB"; if ($conn->query($sql) === TRUE) { echo "Success: In creating a Database for the User. <br/>"; $conn1 = new mysqli($servername, $username, $password, "cs634DM_".$_POST['su_username']."_DB"); $sql1 = "CREATE TABLE Transactions ( Tid INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, TransDateTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )"; $sql2 = "CREATE TABLE TransactionDetails ( Tid INT(6) UNSIGNED, label VARCHAR(25), PRIMARY KEY (Tid,label), FOREIGN KEY (Tid) REFERENCES Transactions(Tid) )"; if ($conn1->query($sql1) === TRUE && $conn1->query($sql2) === TRUE) { echo "Success: In creating a Tables in User_DB. <br/>"; } else { echo "Error creating table: " . $conn1->error; } /* Creating a Login session */ $_SESSION['User_DB'] = "cs634DM_".$_POST['su_username']."_DB"; $_SESSION['username'] = $_POST['su_username']; $_SESSION['logged'] = TRUE; $_SESSION['cart'] = array(); /* Setting up a transaction */ echo "Signup Sucessful!! Redirecting to Shopping Page in 5 seconds."; header("refresh: 5;url=./shopping.php"); $conn1->close(); } } if($_SESSION['logged'] !== TRUE){ echo "Error: Username already exists." .$sql . "<br>" . $conn->error; echo "Signup Unsucessful!! Redirecting to Home page in 5 seconds."; header("refresh: 5;url=./index.php"); } }?>