Advertisement
AleksandarH

Y2S2 - insert.php

May 16th, 2022 (edited)
840
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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="firstname" required>
  11.             Фамилия:            <input type="text" name="lastname" required>
  12.             Адрес:              <input type="text" name="address" required>
  13.             Телефон:            <input type="text" name="phonenumber" required>
  14.             Година на издаване: <input type="text" name="year" required>
  15.             <input type="submit" name="submit" value="Въведи">
  16.         </pre>
  17.     </form>
  18.     <?php
  19.     include 'config.php';
  20.     if (isset($_POST["submit"]))
  21.     {
  22.         $firstname = $_POST["firstname"];
  23.         $lastname = $_POST["lastname"];
  24.         $address = $_POST["address"];
  25.         $phonenumber = $_POST["phonenumber"];
  26.         $year = $_POST["year"];
  27.         if (!empty($firstname) && !empty($lastname) && !empty($address) && !empty($phonenumber) && !empty($year))
  28.         {
  29.             $sql = "INSERT INTO Chitateli (firstname, lastname, address, phonenumber, year) VALUE('$firstname', '$lastname', '$address', '$phonenumber', '$year')";
  30.                     $result = mysqli_query($dbConn, $sql);
  31.                     if (!$result)
  32.                     {
  33.                         die('An ERROR has occured');
  34.                     }
  35.                     echo "MESSAGE > Successfully added data to database";
  36.         }
  37.         else
  38.         {
  39.             echo "ERROR > Please enter on all fields";
  40.         }
  41.     }
  42.     $query = "SELECT * FROM Chitateli";
  43.     $result = mysqli_query($dbConn, $query);
  44.     $count = mysqli_num_rows($result);
  45.     if ($count > 0)
  46.     {
  47.         echo "<table border='2'><tr><th>Номер на читателска карта</th><th>Име</th><th>Фамилия</th><th>Адрес</th><th>Телефон</th><th>Година на издаване</th>";
  48.         while ($row = mysqli_fetch_array($result))
  49.         {
  50.             echo "<tr><td>" . $row["id"] . "</td><td>" . $row['firstname'] . "</td><td>" . $row['lastname'] . "</td><td>" . $row['address'] . "</td><td>" . $row['phonenumber'] . "</td><td>" . $row['year'] . "</td></tr>";
  51.         }
  52.         echo "</table>";
  53.     }
  54.     ?>
  55. </body>
  56. </html>
Advertisement
RAW Paste Data Copied
Advertisement