Advertisement
UniQuet0p1

Untitled

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