Advertisement
UniQuet0p1

Autor-add.php

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