syed2

Error

Jan 1st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1.  
  2. <?php
  3. $fname ="";//First Name
  4. $lname =""; //Last Name
  5. $em ="";//Email
  6. $em2 ="";//Email 2
  7. $password ="";//password
  8. $password2 ="";//password2
  9. $date ="";//signed Up data
  10. $erro_array= array();
  11.  
  12. if (isset($_POST["register_button"])){
  13.  
  14. //registration form Values
  15.  
  16. $fname= strip_tags($_POST["reg_fname"]);//remove HTML Tags
  17. $fname = str_replace(' ', '', $fname); //remove Spaces
  18. $fname = ucfirst(strtolower ($fname)); //upper case to first
  19. $_SESSION ['reg_fname'] =$fname; // stores values of first name in session variable
  20.  
  21. // last name
  22.  
  23. $lname= strip_tags($_POST["reg_lname"]);//remove HTML Tags
  24. $lname = str_replace(' ', '', $lname); //remove Spaces
  25. $lname = ucfirst(strtolower ($lname)); //upper case to first
  26. $_SESSION ['reg_lname'] =$lname; // stores values of last name in session variable
  27.  
  28. //email
  29.  
  30. $em = strip_tags($_POST ["reg_email"]);
  31. $em = str_replace(' ', '',$em);
  32. $em = ucfirst(strtolower ($em));
  33. $_SESSION ['reg_email'] =$em; // stores values of mail id in session variable
  34.  
  35. $em2 = strip_tags($_POST ["reg_email2"]);
  36. $em2 = str_replace(' ', '',$em2);
  37. $em2 = ucfirst(strtolower ($em2));
  38. $_SESSION ['reg_email2'] =$em2; // stores values of mail id2 in session variable
  39.  
  40. // password
  41.  
  42.  
  43. $password = strip_tags($_POST ["reg_password"]);
  44. $password2 = strip_tags($_POST ["reg_password2"]);
  45.  
  46. $date = date("Y-m-d");// this gets the current date
  47. }
  48.  
  49. //check if the emails match
  50. if ($em==$em2) {
  51. //check if emails are in valid format
  52. if (filter_var($em, FILTER_VALIDATE_EMAIL)) {
  53. $em = filter_var($em, FILTER_VALIDATE_EMAIL);
  54.  
  55. //check if email already exists
  56. $e_check = mysqli_query ($con , "SELECT email FROM users WHERE email='$em'" );
  57.  
  58. // count numbers of rows returned
  59. $num_rows = mysqli_num_rows($e_check);
  60. if ($num_rows>0) {
  61.  
  62. array_push($erro_array,"Email Already in Use <br>");
  63.  
  64. }
  65.  
  66. }
  67.  
  68. else {
  69.  
  70. array_push($erro_array, "invalid format <br>") ;
  71. }
  72.  
  73. }
  74. else {
  75. array_push($erro_array, "Your Emails Dont match!<br>" );
  76. }
  77.  
  78. if (strlen($fname)>25|| strlen($fname)<2) {
  79. array_push($erro_array, "your first name must be between 2 and 25 charectors <br>" ) ;
  80.  
  81. }
  82. if (strlen($lname)>25|| strlen($lname)<2) {
  83. array_push($erro_array," your last name must be between 2 and 25 charectors <br>") ;
  84. }
  85.  
  86. if ($password !== $password2) {
  87. array_push($erro_array, "password dont match <br>");
  88.  
  89. }
  90.  
  91. else {
  92. if (preg_match('/[^A-Za-z0-9]/', $password)) {
  93. array_push($erro_array, "your last password can only contain english charector or Number <br>");
  94. }}
  95.  
  96.  
  97. //if(strlen($password > 30 || strlen($password) < 5)) {
  98. //array_push($error_array, "Your password must be betwen 5 and 30 characters<br>");
  99.  
  100.  
  101. if (strlen($password>30||strlen($password)<5)) {
  102. array_push($erro_array, "your password must be between 5 and 30 charector <br>");
  103. }
  104.  
  105. if (empty($erro_array)) {
  106. $password = md5($password); //encrypt password before sending to Database
  107.  
  108. //generate username by concatnating by firstname and lastname
  109.  
  110. $username = strtolower($fname."_". $lname);
  111. $check_username_query = mysqli_query ($con, "SELECT username FROM user WHERE username = '$username'");
  112. $i= 0;
  113. // if user name exists add number to usrname
  114.  
  115. while (mysqli_num_rows($check_username_query)!=0) {
  116. $i++; // add 1 to i
  117.  
  118. $username = $username . "_" . $i;
  119. $check_username_query = mysqli_query($con, "SELECT username FROM user WHERE username = '$username'");
  120.  
  121. }
  122.  
  123. // profile pic assignement
  124.  
  125. $rand = rand(1,2);
  126.  
  127. if ($rand == 1)
  128. $profile_pic= "assets/images/profile_pics/defaults/head_alizarin.png";
  129. else if ($rand==2)
  130. $profile_pic = "assets/images/profile_pics/defaults/head_deep_blu.png";
  131. $query = mysqli_query($con, "INSERT INTO users VALUES ('','$fname','$lname','$em','$em2','$password','$date','$profile_pic' ,'0','0', 'no', ',' )");
  132.  
  133. array_push($erro_array,"<span style='color:#14c800'> you are all set , go ahead and login </span> <br>");
  134.  
  135. //clear session variable
  136.  
  137. $_SESSION['reg_fname'] = '';
  138. $_SESSION['reg_lname'] = '';
  139. $_SESSION['reg_email'] = '';
  140. $_SESSION['reg_email2'] = '';
  141.  
  142.  
  143.  
  144. }
  145. ?>
Add Comment
Please, Sign In to add comment