SHARE
TWEET

Untitled

a guest Apr 29th, 2017 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php  
  2. //including database connection
  3.     include 'connection.php';
  4.  
  5. //checking if form data were sent
  6.     if($_SERVER['REQUEST_METHOD'] == 'POST'){
  7.  
  8. //avoiding sql injections and storing data in variables
  9.     $fname = mysqli_real_escape_string($conn, $_POST['fname']);
  10.     $lname = mysqli_real_escape_string($conn, $_POST['lname']);
  11.     $username = $_POST['username'];
  12.     $email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
  13.     $pass = mysqli_real_escape_string($conn, trim($_POST['pass']));  
  14.     $pass1 = mysqli_real_escape_string($conn, trim($_POST['pass1']));
  15.     $adresa = mysqli_real_escape_string($conn, trim($_POST['adresa']));
  16.     $birth_month = $_POST['birth_month'];
  17.     $birth_day = $_POST['birth_day'];
  18.     $dateofbirth = $_POST['dateofbirth'];
  19.  
  20. //creating $errors array
  21.     $errors = array();
  22.    
  23.     if(empty($fname)){
  24.        
  25. //storing data in array
  26.         $errors[] = "Molimo unesite vase ime";
  27.     }elseif(is_numeric($fname)){
  28.             $errors[] ="Greska prilikom unosa imena";
  29.     }else{
  30.         if(count_chars($fname) < 3){
  31.             $errors[] = "Vase ime ne moze biti krace od tri slova";
  32.         }
  33.     }
  34.     if(empty($lname)){
  35.         $errors[] = "Molimo unesite vase prezime";
  36.     }elseif(is_numeric($lname)){
  37.             $errors[] ="Greska prilikom unosa imena";
  38.     }else{
  39.         if(count_chars($lname) < 3){
  40.             $errors[] = "Vase prezime ne moze biti krace od tri slova";
  41.         }
  42.     }
  43.     if(empty($username)){
  44.         $errors[] = "Molimo unesite vase korisnicko ime";
  45.     }elseif(is_numeric($username)){
  46.             $errors[] ="Greska prilikom unosa imena";
  47.     }else{
  48.         if(count_chars($username) < 4){
  49.             $errors[] = "Vas username ne moze biti krace od tri slova";
  50.         }
  51.     }
  52.     if(empty($email)){
  53.         $errors[] = "Molimo unesite vas email";
  54.     }else{
  55.         if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  56.         $errors[] = "Greska u unosu email adrese";
  57.         }
  58.     }
  59.     if(empty($pass)){
  60.         $errors[] = "Molimo unesite vas password";
  61.     }else{
  62.         if(count_chars($pass) < 6){
  63.             $errors[] = "Password mora imati najmanje sest znakova";
  64.         }
  65.     if(empty($pass1)){
  66.         $errors[] = "Molimo potvrdite vas password";
  67.     }  
  68.     if(empty($birth_month)){
  69.         $errors[] = "Molimo unesite vas mjesec rodjenja";
  70.     }
  71.     if(empty($birth_day)){
  72.         $errors[] = "Molimo unesite vas dan rodjenja";
  73.     }
  74.     if(empty($dateofbirth)){
  75.         $errors[] = "Molimo unesite vasu godinu rodjenja";
  76.     }elseif(!is_numeric($dateofbirth)){
  77.     $errors[] = "Pogresno ste unijeli godinu rodjenja";
  78.     }elseif($dateofbirth < 1900){
  79.         $errors[] = "Pogresno ste unijeli godinu rodjenja, broj je preveliki";
  80.     }  
  81.     if(empty($adresa)){
  82.             $errors[] = "Molimo unesite vasu adresu";
  83.     }
  84.     $q = "SELECT * FROM user WHERE username = '{$username}'";
  85.     $r = mysqli_query($conn, $q);
  86.     if(mysqli_num_rows($r) > 0){
  87.      die('<h2 class = "error">'. 'Username je vec zauzet. Molimo uzmite drugi' . '</h2>');
  88.     }      
  89.     $q = "SELECT * FROM user WHERE email = '{$email}'";
  90.     $r = mysqli_query($conn, $q);
  91.     if(mysqli_num_rows($r) > 0){
  92.      die('<h2 class = "error">'. 'Korisnik sa ovom email adresom je vec registrovan. Ukoliko ste zaboravili sifru, kontaktirajte nas' . '</h2>');
  93.     }  
  94.     if($pass != $pass1){
  95.         $errors[] = 'Sifre se ne poklapaju. Molimo pokusajte ponovo';
  96.     }
  97.  
  98. //checking if $errors is empty - if not cheking where did error occurred
  99.     if(empty($errors)){
  100.     $q = "INSERT INTO user (name, last_name, username, email,
  101.     password, birth_month, birth_day, dateofbirth, adresa, reg_date)
  102.     VALUES ('$fname','$lname','$username','$email',sha1('$pass'),'$birth_month','$birth_day', '$dateofbirth','$adresa', now())";
  103.     $r = mysqli_query($conn, $q);  
  104.     if($r){
  105.     echo "<p>Uspjesno ste registrovani"  . " "  . $fname .  " " . $lname . "</p>";
  106.     }
  107.     }else{
  108.     echo '<h2 class = "error">'. "Sljedece greske su pronadjene:" . '</h2>' ;
  109.     foreach($errors as $msg){
  110.     echo '<h2 class = "error">' . $msg . '</h2>' . '<br>';
  111.                                                     }
  112.     }
  113.      
  114. }
  115.    
  116. }
  117.  
  118. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top