Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include ("db_fncs.php");
  4. include ("login-data.php");
  5. try{
  6. $conn = new PDO(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD);
  7.  
  8. }
  9. catch (PDOException $exception)
  10. {
  11. echo "Oh no, there was a problem" . $exception->getMessage();
  12. }
  13.  
  14.  
  15. //get the form data
  16. $name=trim($_POST['name']);
  17. $username=trim($_POST['username']);
  18. $password=password_hash(test($_POST['password']));
  19. $contact=trim($_POST['contactNumber']);
  20.  
  21. //$validate the form data
  22. $validForm=true;
  23.  
  24. if (isset($_POST['occupation'])) {
  25. $occupation = $_POST['occupation'];
  26. }
  27.  
  28. if (isset($_POST['role'])) {
  29. $role = $_POST['role'];
  30. }
  31.  
  32. if (isset($_POST['pic'])) {
  33. $picture = $_POST['pic'];
  34. }
  35.  
  36. if (empty($_POST["name"]))
  37. {
  38. $nameErr = "*required";
  39. $validForm=false;
  40. }
  41. if (empty($_POST["username"]))
  42. {
  43. $userErr = "*required";
  44. $validForm=false;
  45. }
  46. if (empty($_POST["password"]))
  47. {
  48. $passErr = "*required";
  49. $validForm=false;
  50. }
  51. if (empty($_POST["contactNumber"]))
  52. {
  53. $ContactErr = "*required";
  54. $validForm=false;
  55. }
  56. if (empty($_POST["occupation"]))
  57. {
  58. $occupationErr = "*required";
  59. $validForm=false;
  60. }
  61.  
  62.  
  63.  
  64.  
  65. if (strlen($username) > 15)
  66. {
  67. $userErr = "*username must be under 15 characters";
  68. $validForm=false;
  69. }
  70. if (strlen($password) > 15)
  71. {
  72. $passErr = "*password must be under 15 characters";
  73. $validForm=false;
  74. }
  75. //insert into the database
  76.  
  77. if (!$validForm) {
  78.  
  79. include("account.php");
  80. return false;
  81.  
  82. }
  83. else
  84. {
  85.  
  86.  
  87. $conn=getConn();
  88. $successRegister=selectNew($conn,$name,$username,$password,$contact,$occupation,$role,$picture);
  89. if ($successRegister) {
  90. $error = "Congrats! You are now registered";
  91. include("account.php");
  92. }
  93. $conn=NULL; //close the connection
  94.  
  95. }
  96.  
  97.  
  98.  
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement