Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include ("db_fncs.php");
- include ("login-data.php");
- try{
- $conn = new PDO(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD);
- }
- catch (PDOException $exception)
- {
- echo "Oh no, there was a problem" . $exception->getMessage();
- }
- //get the form data
- $name=trim($_POST['name']);
- $username=trim($_POST['username']);
- $password=password_hash(test($_POST['password']));
- $contact=trim($_POST['contactNumber']);
- //$validate the form data
- $validForm=true;
- if (isset($_POST['occupation'])) {
- $occupation = $_POST['occupation'];
- }
- if (isset($_POST['role'])) {
- $role = $_POST['role'];
- }
- if (isset($_POST['pic'])) {
- $picture = $_POST['pic'];
- }
- if (empty($_POST["name"]))
- {
- $nameErr = "*required";
- $validForm=false;
- }
- if (empty($_POST["username"]))
- {
- $userErr = "*required";
- $validForm=false;
- }
- if (empty($_POST["password"]))
- {
- $passErr = "*required";
- $validForm=false;
- }
- if (empty($_POST["contactNumber"]))
- {
- $ContactErr = "*required";
- $validForm=false;
- }
- if (empty($_POST["occupation"]))
- {
- $occupationErr = "*required";
- $validForm=false;
- }
- if (strlen($username) > 15)
- {
- $userErr = "*username must be under 15 characters";
- $validForm=false;
- }
- if (strlen($password) > 15)
- {
- $passErr = "*password must be under 15 characters";
- $validForm=false;
- }
- //insert into the database
- if (!$validForm) {
- include("account.php");
- return false;
- }
- else
- {
- $conn=getConn();
- $successRegister=selectNew($conn,$name,$username,$password,$contact,$occupation,$role,$picture);
- if ($successRegister) {
- $error = "Congrats! You are now registered";
- include("account.php");
- }
- $conn=NULL; //close the connection
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement