Advertisement
Guest User

Untitled

a guest
Jul 31st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. <?php
  2.  
  3. $error = null;
  4. $success = false;
  5.  
  6. if (isset($_GET['submitButton'])) {
  7.  
  8. $servername = "localhost";
  9. $username = "root";
  10. $password = "";
  11. $dbname = "php_vaje";
  12.  
  13. // Create connection
  14. $conn = new mysqli($servername, $username, "", $dbname);
  15. // Check connection
  16. if ($conn->connect_error) {
  17. $error = "Mysql base is not running, please try again later.";
  18. }
  19.  
  20. if ($error === null) {
  21. $name = $_GET['nameBox'];
  22. $password = $_GET['passwordBox'];
  23. $passwordRepeat = $_GET['passwordBox2'];
  24.  
  25. $sql = "SELECT ID FROM uporabnik WHERE name='$name'";
  26. $result = $conn->query($sql);
  27.  
  28. if ($result->num_rows > 0) {
  29. $error = "This username is already taken.";
  30. }
  31.  
  32. if ($password !== $passwordRepeat) {
  33. if ($error !== null) {
  34. $error .= "<br />Passwords do not match.";
  35. }
  36. else {
  37. $error = "Passwords do not match.";
  38. }
  39. }
  40.  
  41. if ($error === null) {
  42. $sql = "INSERT INTO uporabnik (name, password) VALUES ('$name', '$password')";
  43.  
  44. if ($conn->query($sql) === TRUE) {
  45. $success = true;
  46. } else {
  47. $error = "Something went wrong, please try again later.";
  48. }
  49. }
  50.  
  51. $conn->close();
  52. }
  53. }
  54.  
  55. ?>
  56.  
  57. <!DOCTYPE html>
  58. <html>
  59. <head>
  60. <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  61. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  62.  
  63. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
  64. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
  65.  
  66. <title>Register page</title>
  67. </head>
  68. <body>
  69. <div class="row">
  70. <div class="offset-lg-5 col-lg-2 offset-2 col-8">
  71. <div class="card mt-5">
  72. <div class="card-body">
  73.  
  74. <?php
  75. if($success) {
  76. include 'userLogin.php';
  77. ?>
  78. <div class="alert alert-success" role="alert">
  79. Thank you for registering!
  80.  
  81. </div>
  82. <?php
  83. }
  84. else {
  85. ?>
  86.  
  87. <?php
  88. if($error !== null) {
  89. ?>
  90. <div class="alert alert-danger" role="alert">
  91. <?php echo $error ?>
  92. </div>
  93. <?php
  94. }
  95. ?>
  96.  
  97. <form action="register.php" method="get">
  98. <div class="form-group">
  99. <label for="exampleInputEmail1">Username</label>
  100. <input name="nameBox" type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Username" required>
  101. </div>
  102. <div class="form-group">
  103. <label for="exampleInputPassword1">Password</label>
  104. <input name="passwordBox" type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" required>
  105. </div>
  106. <div class="form-group">
  107. <label for="exampleInputPassword1">Repeat password</label>
  108. <input name="passwordBox2" type="password" class="form-control" id="exampleInputPassword1" placeholder="Repeat password" required>
  109. </div>
  110. <center>
  111. <button name="submitButton" type="submit" class="btn btn-primary">Register</button>
  112. </center>
  113. </form>
  114.  
  115. <?php
  116. }
  117. ?>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </body>
  123. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement