Guest User

Untitled

a guest
Apr 2nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. // variable declaration
  5. $username = "";
  6. $country = "";
  7. $email = "";
  8. $first_name = "";
  9. $last_name = "";
  10. $birth_date = "";
  11. $spol = "";
  12. $country = "";
  13. $errors = array();
  14.  
  15.  
  16.  
  17. // connect to database
  18. $db = mysqli_connect('localhost', 'root', '', 'trikoder');
  19.  
  20. // REGISTER USER
  21. if (isset($_POST['reg_user'])) {
  22. // receive all input values from the form
  23. $username = mysqli_real_escape_string($db, $_POST['username']); //escape epecial strings..
  24. $country = mysqli_real_escape_string($db, $_POST['country']); //escape epecial strings..
  25.  
  26. $first_name = mysqli_real_escape_string($db, $_POST['first_name']); //escape epecial strings..
  27. $last_name = mysqli_real_escape_string($db, $_POST['last_name']); //escape epecial strings..
  28. $birth_date = mysqli_real_escape_string($db, $_POST['birth_date']); //escape epecial strings..
  29. $spol = mysqli_real_escape_string($db, $_POST['spol']); //escape epecial strings..
  30.  
  31. $email = mysqli_real_escape_string($db, $_POST['email']); //escape epecial strings..
  32. $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
  33. $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
  34.  
  35. // Jako jednostavna validacija podataka. Provjera se samo da li je polje popunjeno.
  36. if (empty($username)) { array_push($errors, "Korisničko ime je obavezno"); }
  37. if (empty($country)) { array_push($errors, "Država je obavezno"); }
  38.  
  39. if (empty($first_name)) { array_push($errors, "Ime je obavezno"); }
  40. if (empty($last_name)) { array_push($errors, "Prezime je obavezno"); }
  41. if (empty($birth_date)) { array_push($errors, "Datum rođenja je obavezno"); }
  42. if (empty($spol)) { array_push($errors, "Spol je obavezno"); }
  43.  
  44. if (empty($email)) { array_push($errors, "E-mail je obavezan"); }
  45. if (empty($password_1)) { array_push($errors, "Lozinka je obavezna"); }
  46.  
  47. if ($password_1 != $password_2) {
  48. array_push($errors, "Lozinke se ne podudaraju");
  49. }
  50.  
  51. // Ako nema greške, kreiraj novog korisnika.
  52. if (count($errors) == 0) {
  53.  
  54. $password = md5($password_1);//encrypt the password before saving in the database
  55. $query = "INSERT INTO users (username, first_name, last_name, email, birth_date, password, spol, country)
  56. VALUES('$username', '$first_name', '$last_name', '$email', '$birth_date', '$password', '$spol', '$country')";
  57.  
  58. echo "<pre>Debug: $query</pre> ";
  59. $result = mysqli_query($db, $query);
  60. if ( false===$result ) {
  61. printf("error: %s\n", mysqli_error($db));
  62. }
  63. else {
  64. echo "<pre>korisnik registriran</pre> ";
  65. }
  66.  
  67. }
  68.  
  69. }
  70.  
  71.  
  72. ?>
Add Comment
Please, Sign In to add comment