/new_teacher.php

https://gitlab.com/javednayeem/grecenter · PHP · 89 lines · 60 code · 14 blank · 15 comment · 5 complexity · eceb4f25e173a8a1e83cdce438c4018f MD5 · raw file

  1. <?php require_once("includes/heder.php"); ?>
  2. <?php require_once("includes/db_con.php"); ?>
  3. <?php require_once("includes/function.php"); ?>
  4. <?php require_once("includes/validation_functions.php"); ?>
  5. <?php if($_SESSION["username"]!="gre"){
  6. redirect_to("login.php");
  7. }
  8. ?>
  9. <?php
  10. if(isset($_POST["submit"])){
  11. $required_field = array("username", "password");
  12. validate_presence($required_field);
  13. $fields_with_max_length = array("username" => 30);
  14. validate_max_length($fields_with_max_length);
  15. if(empty($errors)){
  16. //$username = $_POST["username"];
  17. //$hashed_password = $_POST["password"];
  18. //$hashed_password = $_POST["password"];
  19. //$username = mysql_real_escape_string(stripslashes(mysql_prep($_POST["username"])));
  20. //$username = mysql_prep($_POST["username"]);
  21. //$hashed_password = password_encrypt($_POST["password"]);
  22. $username = mysql_prep($_POST["username"]);
  23. $hashed_password = crypt(md5($_POST["password"]),st);
  24. //$hashed_password = password_encrypt($_POST["password"]);
  25. //$hashed_password = md5($_POST["password"]);
  26. //$hashed_password = mysql_real_escape_string(stripslashes(md5(uniqid(mt_rand($_POST["password"]),true))));
  27. //$hashed_password = md5(uniqid(mt_rand($_POST["password"]),true));
  28. //$result = mysql_query("INSERT INTO admin (`name`,`pass`)VALUES('{$username}','{$hashed_password}')");
  29. $query = "INSERT INTO admin ( ";
  30. $query .= "name, pass , role, active";
  31. $query .= ") VALUES ( ";
  32. $query .= "'{$username}', '{$hashed_password}', 'Teacher', 1";
  33. $query .= ")";
  34. if (!mysql_query($query)){
  35. die('Error: ' . mysql_error(). mysql_errno());
  36. }
  37. if($query){
  38. //success
  39. $_SESSION["message"] = "Teacher created.";
  40. redirect_to("login.php");
  41. }else{
  42. //failed
  43. $_SESSION["message"] = "Teacher creation failed.";
  44. }
  45. }
  46. }else{
  47. // Probably get request
  48. }
  49. //----------Single form submission processing finishing line-------------------------
  50. ?>
  51. <?php $layout_context = "Admin"; ?>
  52. <div class="container" id="new_admin">
  53. <div class="col-md-12 col-xs-12">
  54. <?php echo message(); ?>
  55. <?php echo form_errors($errors); ?>
  56. <h2 style="text-align:center;">Create Teacher</h2>
  57. <form role="form" action="new_teacher.php" method="post">
  58. <div class="from-gorup">
  59. <p>User Name:
  60. <input class="form-control" type="text" name="username" value="" />
  61. </p>
  62. </div>
  63. <div class="from-group">
  64. <p>Password:
  65. <input class="form-control" type="password" name="password" value="" />
  66. </p>
  67. </div>
  68. <input type="submit" class="btn btn-default" name="submit" value="Create Teacher" />
  69. <a class="btn btn-default pull-right" href="logout.php">Cancel</a>
  70. </form>
  71. <br>
  72. </div>
  73. </div>
  74. </body>
  75. </html>