Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function addEmployee($id,$title, $grade){
- //ищит следубщее ид
- $maxId = 0;
- $lines = file("books.txt");
- foreach ($lines as $line){
- $employee = explode(";", $line);
- if(intval($employee[0]) > $maxId){
- $maxId = intval($employee[0]);
- }
- }
- //пишет файл
- $newEmployee =($maxId + 1) . urlencode($id) . ";" . urlencode($title) . ";" . urlencode($grade) . PHP_EOL;
- file_put_contents("books.txt", $newEmployee, FILE_APPEND);
- }
- if ($_SERVER["REQUEST_METHOD"] === "POST"){
- $id = $_POST["id"];
- $title = $_POST["title"];
- $grade = $_POST["grade"];
- //сохранение
- addEmployee($id, $title, $grade);
- header("Location: ../index.php");
- }
- ?>
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <link rel="stylesheet" type="text/css" href="styles.css">
- <title>LisaAutor</title>
- </head>
- <body id="book-form-page">
- <div id="root">
- <nav>
- <a href="../index.php" id="book-list-link">Raamatud</a>
- <a href="book-add.php" id="book-form-link">Lisa raamat</a>
- <a href="author-list.php" id="author-list-link">Autorid</a>
- <a href="author-add.php" id="author-form-link">Lisa autor</a>
- </nav>
- <main>
- <form id="input-form" method="post">
- <input name="id" type="hidden" value="">
- <div class="label">Pealkiri</div>
- <div class="input"><input id="title" name="title" type="text" value=""></div>
- <div class="label">Hinne:</div>
- <div class="input">
- <input type="radio" name="grade" value="1">1
- <input type="radio" name="grade" value="2">2
- <input type="radio" name="grade" value="3">3
- <input type="radio" name="grade" value="4">4
- <input type="radio" name="grade" value="5">5
- </div>
- <div class="br"></div>
- <div class="label">Loetud</div>
- <div class="input"><input id="isRead" name="isRead" type="checkbox"/></div>
- <div class="br"></div>
- <div class="label"></div>
- <div class="input button2">
- <td><input class="button" name="submitButton" type="submit" value="Salvesta"></td>
- </div>
- </form>
- </main>
- <footer>
- ICD0007 Näidisrakendus
- </footer>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement