Guest User

Untitled

a guest
May 10th, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. $db = mysqli_connect('localhost', 'id13157365_ladashboard', 'mAryOXCp/=K4/NqB', 'id13157365_lafilipinadatabase');
  6.  
  7. $username = "";
  8.  
  9. $name="";
  10.  
  11. $location="";
  12.  
  13. $errors = array();
  14.  
  15.  
  16.  
  17. if (isset($_POST['add_btn'])) {
  18.  
  19. add_user();
  20.  
  21. }
  22.  
  23.  
  24.  
  25. function add_user(){
  26.  
  27. global $db , $errors, $username;
  28.  
  29.  
  30.  
  31. $username = e($_POST['username']);
  32.  
  33. $password_1 = e($_POST['password_1']);
  34.  
  35. $password_2 = e($_POST['password_2']);
  36.  
  37.  
  38.  
  39. if (empty($username)) {
  40.  
  41. array_push($errors, "Username is required");
  42.  
  43. }
  44.  
  45. if (empty($password_1)) {
  46.  
  47. array_push($errors, "Password is required");
  48.  
  49. }
  50.  
  51. if ($password_1 != $password_2) {
  52.  
  53. array_push($errors, "The two passwords do not match");
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. if (count($errors) == 0) {
  62.  
  63. $password = md5($password_1,true);
  64.  
  65.  
  66.  
  67. if (isset($_POST['user_type'])) {
  68.  
  69. $user_type = e($_POST['user_type']);
  70.  
  71. $query = "INSERT INTO users (username, password , user)
  72.  
  73. VALUES('$username', '$password', '$user_type')";
  74.  
  75. mysqli_query($db, $query);
  76.  
  77. header('location: renew.php');
  78.  
  79. }
  80.  
  81. }
  82.  
  83. }
  84.  
  85.  
  86.  
  87. function e($val){
  88.  
  89. global $db;
  90.  
  91. return mysqli_real_escape_string($db, trim($val));
  92.  
  93. }
  94.  
  95.  
  96.  
  97. if (isset($_POST['login_btn'])) {
  98.  
  99. login();
  100.  
  101. }
  102. function login(){
  103. global $db, $username, $errors;
  104.  
  105.  
  106. $username = e($_POST['username']);
  107. $password = e($_POST['password']);
  108. if (count($errors) == 0) {
  109. $password = md5($password,true);
  110.  
  111. $query = "SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1";
  112. $results = mysqli_query($db, $query);
  113.  
  114. if (mysqli_num_rows($results) == 1) {
  115. $logged_in_user = mysqli_fetch_assoc($results);
  116. if ($logged_in_user['user'] == 'admin') {
  117. header('location: AND.html');
  118. }else{
  119. header('location: AND.html');
  120. }
  121. }else {
  122. array_push($errors, "Wrong username/password combination");
  123. }
  124. }
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. if(isset($_POST['searchb'])){
  133.  
  134. global $db,$name,$location;
  135.  
  136. $searched=$_POST['Searcht'];
  137.  
  138.  
  139.  
  140. $query_avail1="select * from dummy_names where name='$searched'";
  141.  
  142. $result_avail1=mysqli_query($db,$query_avail1);
  143.  
  144.  
  145.  
  146. if(mysqli_num_rows($result_avail1)==1){
  147.  
  148. $available=mysqli_fetch_assoc($result_avail1);
  149.  
  150. $name=$available['name'];
  151.  
  152. $location=$available['location'];
  153.  
  154. }
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. }
  163.  
  164. if (isset($_POST['ren_btn'])){
  165.  
  166. renew();
  167.  
  168. }
  169.  
  170.  
  171.  
  172. function renew(){
  173.  
  174. global $db,$errors;
  175.  
  176.  
  177.  
  178. $name=$_POST['name'];
  179.  
  180. $location=$_POST['location'];
  181.  
  182. $renewdate=$_POST['rendate'];
  183.  
  184. $expdate=$_POST['expdate'];
  185.  
  186. $or=$_POST['or'];
  187.  
  188.  
  189.  
  190. if(empty($name)){
  191.  
  192. array_push($errors, "Please Search Name first");
  193.  
  194. }
  195.  
  196. if(empty($renewdate)){
  197.  
  198. array_push($errors, "Please fill up the Renew Date");
  199.  
  200. }
  201.  
  202.  
  203.  
  204. if(empty($renewdate)){
  205.  
  206. array_push($errors, "Please fill up the Expiration Date");
  207.  
  208. }
  209.  
  210. if(empty($or)){
  211.  
  212. array_push($errors, "Please fill up the OR#");
  213.  
  214. }
  215.  
  216. if($renewdate>$expdate){
  217.  
  218. array_push($errors, "Please check the expiration date");
  219.  
  220. }
  221.  
  222.  
  223.  
  224. if(count($errors)==0){
  225.  
  226. $query = "INSERT INTO renew (name, location , renew_date, expiration_date, OR_num)
  227.  
  228. VALUES('$name', '$location', '$renewdate', '$expdate', '$or')";
  229.  
  230. mysqli_query($db, $query);
  231.  
  232.  
  233. }
  234.  
  235.  
  236.  
  237. }
  238.  
  239.  
  240.  
  241. function display_error() {
  242.  
  243. global $errors;
  244.  
  245.  
  246.  
  247. if (count($errors) > 0){
  248.  
  249. echo '<div class="error">';
  250.  
  251. foreach ($errors as $error){
  252.  
  253. echo $error .'<br>';
  254.  
  255. }
  256.  
  257. echo '</div>';
  258.  
  259. }
  260.  
  261. }
Add Comment
Please, Sign In to add comment