Advertisement
Guest User

Untitled

a guest
May 15th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <html>
  2. <head>>
  3. <?php
  4. include '../includes/head.php';
  5.  
  6. $username = $_POST['username'];
  7. $publicname = $_POST['publicname'];
  8. $password = $_POST['password'];
  9. ?>
  10. </head>
  11. <body>
  12. <?php
  13.  
  14. if(isset($_POST['submit'])){
  15. if(strlen($_POST['username']) < 3){
  16. $error[] = 'Uživatelské jméno je příliš krátké (minimální počet znaků je 3).';
  17. } else {
  18. $stmt = $db->prepare('SELECT username FROM user WHERE username = $username');
  19. $stmt->execute(array(':username' => $_POST['username']));
  20. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  21.  
  22. if(!empty($row['username'])){
  23. $error[] = 'Uživatelské jméno je již používáno.';
  24. }
  25.  
  26. }
  27. if(strlen($_POST['password']) < 3){
  28. $error[] = 'Heslo je příliš krátké (minimální počet znaků je 3).';
  29. }
  30.  
  31. if(!isset($error)){
  32.  
  33. //hash the password
  34. $hashedpassword = md5($password);
  35.  
  36. $sql = "INSERT INTO user (username, publicname, password) VALUES ('$username','$publicname','$hashedpassword')";
  37. }
  38.  
  39.  
  40.  
  41. //check for any errors
  42. if(isset($error)){
  43. foreach($error as $error){
  44. echo '<p class="bg-danger">'.$error.'</p>';
  45. }
  46. }
  47. echo '<a href=\"../index.php\">Zpět</a>';
  48. ?>
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement