Advertisement
AleksandarH

Y2S2 - MySQLi/PHP (input.php)

May 15th, 2022
1,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="UTF-8">
  5.         <title>Input</title>
  6.     </head>
  7. <body>
  8.     <form action="" method="POST">
  9.         <pre>
  10.             Заглавие:          <input type="text" name="title" required>
  11.             Автор:               <input type="text" name="author" required>
  12.             Издателство:    <input type="text" name="publisher" required>
  13.             Година:             <input type="text" name="year" required>
  14.             <input type="submit" name="submit" value="Въведи">
  15.         </pre>
  16.     </form>
  17.     <?php
  18.     include 'config.php';
  19.     if (isset($_POST["submit"]))
  20.     {
  21.         $title = $_POST["title"];
  22.         $author = $_POST["author"];
  23.         $publisher = $_POST["publisher"];
  24.         $year = $_POST["year"];
  25.         if (!empty($title) && !empty($author) && !empty($publisher) && !empty($year))
  26.         {
  27.             $sql = "INSERT INTO books (title, author, publisher, year) VALUE('$title', '$author', '$publisher', '$year')";
  28.                     $result = mysqli_query($dbConn, $sql);
  29.                     if (!$result)
  30.                     {
  31.                         die('Грешка!');
  32.                     }
  33.                     echo "Добавихте един запис!";
  34.         }
  35.         else
  36.         {
  37.             echo "не сте въвели всички данни!";
  38.         }
  39.     }
  40. ?>
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement