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