A simple php website which displays quotes on pictures of pandas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.3 KiB

  1. <?php
  2. if($admin)
  3. {
  4. $errors = array();
  5. if(isset($_POST['newUser']))
  6. {
  7. // echo '**********';
  8. $i_first = mysqli_real_escape_string($dbc, trim($_POST['first']));
  9. $i_last = mysqli_real_escape_string($dbc, trim($_POST['last']));
  10. $i_pass = mysqli_real_escape_string($dbc, trim($_POST['pass']));
  11. $i_user = mysqli_real_escape_string($dbc, trim($_POST['user_name']));
  12. if($i_first && $i_last && $i_pass && $i_user)
  13. {
  14. $q = "select user_id from users where user_name='$i_user'";
  15. $r = mysqli_query($dbc, $q);
  16. if(@mysqli_num_rows($r) == 1)
  17. {
  18. $errors['name'] = "That user name is already in use.";
  19. }
  20. }
  21. else
  22. {
  23. $errors['input'] = "Please fill in all fields!";
  24. }
  25. if(empty($errors))
  26. {
  27. $passcom = $i_pass . $i_first;
  28. $passcom = SHA1($passcom);
  29. if(isset($_POST['admin']))
  30. {
  31. $adminn = "true";
  32. }
  33. else
  34. {
  35. $adminn = "false";
  36. }
  37. $q = "insert into users(first_name, last_name, user_name, pass, registration_date, admin) values ('$i_first', '$i_last' , '$i_user', '$passcom', now(), $adminn)";
  38. //echo $q;
  39. $r = mysqli_query($dbc, $q);
  40. header("Location: admin.php");
  41. }
  42. }
  43. echo '<h1 class="w3-text-teal"><center>Add User</center></h1>';
  44. echo '<form action="admin.php" method ="post" class="w3-container w3-card-4">
  45. <div class="w3-group">
  46. <input class="w3-input" type="text" name="user_name" required>
  47. <label class="w3-label w3-validate">User Name</label>
  48. </div>
  49. <div class="w3-group">
  50. <input class="w3-input" type="text" name="first" required>
  51. <label class="w3-label w3-validate">First Name</label>
  52. </div>
  53. <div class="w3-group">
  54. <input class="w3-input" type="text" name="last" required>
  55. <label class="w3-label w3-validate">Last Name</label>
  56. </div>
  57. <div class="w3-group">
  58. <input class="w3-input" type="password" name="pass" maxlength="20" required>
  59. <label class="w3-label w3-validate">Password</label>
  60. </div>
  61. <input class="w3-check" type="checkbox" name="admin">
  62. <label class="w3-validate">Admin<label>
  63. <p><input type="submit" name="Submit" value="Add User" class="w3-padding-16 w3-hover-dark-grey w3-btn-block w3-center-align" /></p>
  64. <input type="hidden" name="newUser" value="TRUE" />
  65. </form>';
  66. foreach($errors as $msg)
  67. {
  68. echo " - $msg<br />";
  69. }
  70. }
  71. ?>