Advertisement
Guest User

Untitled

a guest
May 20th, 2018
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.16 KB | None | 0 0
  1. <body>
  2. <?php
  3. $servername = "127.0.0.1";
  4. $username = "root";
  5. $password = "root";
  6. $dbname = "cities";
  7.  
  8. // Create connection
  9. $conn = new mysqli($servername, $username, $password, $dbname);
  10. // Check connection
  11. if ($conn->connect_error) {
  12.     die("Connection failed: " . $conn->connect_error);
  13. }
  14. ?>
  15. <div class="row">
  16.     <div class="offset-md-3 col-md-6">
  17.         <div class="container">
  18.             <!-- Card -->
  19.             <div class="card">
  20.                 <h3 class="card-header primary-color white-text">Lab 6</h3>
  21.                 <div class="card-body">
  22.  
  23.                     <form method="POST" name="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
  24.  
  25.  
  26.                         <div class="md-form form-sm">
  27.                             <i class="fa fa-pencil prefix"></i>
  28.                             <input type="text" id="cities" class="form-control form-control-sm" required name="cities"
  29.                             >
  30.                             <label for="cities">Enter cities</label>
  31.                         </div>
  32.                         <?php
  33.                         $cities_info = array(
  34.                             "Lviv" => "Lviv is a city in which I live.\n",
  35.                             "Kyiv" => "Kyiv is the capital of Ukraine.\n",
  36.                             "London" => "London is the capital of Great Britain\n",
  37.                             "New York" => "NY is just a funny place.\n",
  38.                         )
  39.                         ?>
  40.  
  41.                         <div class="md-form form-sm">
  42.                             <i class="fa fa-envelope prefix"></i>
  43.                             <textarea id="message" class="md-textarea form-control">
  44.                             <?php
  45.                             if (isset($_POST['cities'])) {
  46.                                 $data = preg_split('/\s+/', $_POST['cities']);
  47.                                 foreach ($data as $city) {
  48.                                     $sql = "SELECT * FROM cities_info WHERE city_name='$city'";
  49.                                     $result = $conn->query($sql);
  50.                                     if ($result->num_rows > 0) {
  51.                                         // output data of each row
  52.                                         while ($row = $result->fetch_assoc()) {
  53.                                             echo "$city: " . $row["city_information"] . "\n";
  54.                                         }
  55.                                     } else {
  56.                                         echo "$city: no info found\n";
  57.                                     }
  58.  
  59.                                 }
  60.                             }
  61.                             $conn->close();
  62.                             ?>
  63.                     </textarea>
  64.                             <label for="message">Info</label>
  65.                         </div>
  66.  
  67.                         <button type="submit" id="submit" class="btn btn-primary text-center mt-4 mb-2">Send
  68.                             <i class="fa fa-send ml-2"></i>
  69.                         </button>
  70.  
  71.  
  72.                     </form>
  73.                 </div>
  74.             </div>
  75.         </div>
  76.     </div>
  77. </div>
  78. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement