Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <body>
- <?php
- $servername = "127.0.0.1";
- $username = "root";
- $password = "root";
- $dbname = "cities";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- ?>
- <div class="row">
- <div class="offset-md-3 col-md-6">
- <div class="container">
- <!-- Card -->
- <div class="card">
- <h3 class="card-header primary-color white-text">Lab 6</h3>
- <div class="card-body">
- <form method="POST" name="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
- <div class="md-form form-sm">
- <i class="fa fa-pencil prefix"></i>
- <input type="text" id="cities" class="form-control form-control-sm" required name="cities"
- >
- <label for="cities">Enter cities</label>
- </div>
- <?php
- $cities_info = array(
- "Lviv" => "Lviv is a city in which I live.\n",
- "Kyiv" => "Kyiv is the capital of Ukraine.\n",
- "London" => "London is the capital of Great Britain\n",
- "New York" => "NY is just a funny place.\n",
- )
- ?>
- <div class="md-form form-sm">
- <i class="fa fa-envelope prefix"></i>
- <textarea id="message" class="md-textarea form-control">
- <?php
- if (isset($_POST['cities'])) {
- $data = preg_split('/\s+/', $_POST['cities']);
- foreach ($data as $city) {
- $sql = "SELECT * FROM cities_info WHERE city_name='$city'";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while ($row = $result->fetch_assoc()) {
- echo "$city: " . $row["city_information"] . "\n";
- }
- } else {
- echo "$city: no info found\n";
- }
- }
- }
- $conn->close();
- ?>
- </textarea>
- <label for="message">Info</label>
- </div>
- <button type="submit" id="submit" class="btn btn-primary text-center mt-4 mb-2">Send
- <i class="fa fa-send ml-2"></i>
- </button>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement