Advertisement
UniQuet0p1

author add

Nov 17th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. <?php
  2. function addEmployee($id,$firstName, $lastName, $grade){
  3. $maxId = 0;
  4. $lines = file("authors.txt");
  5. foreach ($lines as $line){
  6. $employee = explode(";", $line);
  7. if(int($employee[0]) > $maxId){
  8. $maxId = int($employee[0]);
  9. }
  10. }
  11.  
  12. $newEmployee =($maxId + 1). $id . ";" . $firstName . ";" . $lastName . ";" . $grade . PHP_EOL;
  13. file_put_contents("authors.txt", $newEmployee, FILE_APPEND);
  14.  
  15. }
  16.  
  17. if ($_SERVER["REQUEST_METHOD"] === "POST"){
  18. $id = $_POST["id"];
  19. $firstName = $_POST["firstName"];
  20. $lastName = $_POST["lastName"];
  21. $grade = $_POST["grade"];
  22.  
  23. addEmployee($id, $firstName, $lastName, $grade);
  24. }
  25. ?>
  26.  
  27. <!doctype html>
  28. <html lang="en">
  29. <head>
  30. <meta charset="utf-8">
  31. <link rel="stylesheet" type="text/css" href="styles.css">
  32. <title>LisaAuthor</title>
  33. </head>
  34. <body id="author-form-page">
  35.  
  36. <div id="root">
  37.  
  38. <nav>
  39. <div>
  40. <a href="../index.php" id="book-list-link">Raamatud</a>
  41. <a href="book-add.php" id="book-form-link">Lisa raamat</a>
  42. <a href="author-list.php" id="author-list-link">Autorid</a>
  43. <a href="author-add.php" id="author-form-link">Lisa autor</a>
  44. </div>
  45.  
  46. </nav>
  47.  
  48. <main>
  49.  
  50.  
  51. <form id="input-form" method="post">
  52.  
  53. <input name="id" type="hidden" value="">
  54.  
  55. <div class="label">Eesnimi:</div>
  56. <div class="input"><input id="firstName" name="firstName" value="" type="text"/></div>
  57.  
  58. <div class="label">Perkonnanimi:</div>
  59. <div class="input"><input id="lastName" name="lastName" value="" type="text"/></div>
  60.  
  61. <div class="label">Hinne:</div>
  62. <div class="input">
  63.  
  64. <input type="radio" name="grade" value="1">1
  65. <input type="radio" name="grade" value="2">2
  66. <input type="radio" name="grade" value="3">3
  67. <input type="radio" name="grade" value="4">4
  68. <input type="radio" name="grade" value="5">5
  69. </div>
  70.  
  71. <div class="br"></div>
  72.  
  73. <div class="label"></div>
  74. <div class="input button2">
  75. <input name="submitButton" type="submit" value="Salvesta">
  76. </div>
  77.  
  78. </form>
  79.  
  80.  
  81. </main>
  82.  
  83. <footer>
  84. ICD0007 Näidisrakendus
  85.  
  86. </footer>
  87.  
  88. </div>
  89.  
  90. </body>
  91. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement