0byt3m1n1
Path:
C:
/
wamp64
/
www
/
crop
/
Crops
/
[
Home
]
File: crop.php
<?php session_start(); $servername = "localhost"; $username = "root"; $password = ""; $dbname = "crops"; $conn = new mysqli($servername, $username, $password, $dbname); if (isset($_POST['submit'])) { $selectedCrop = $_POST['crop']; $pes = $_POST['Pests']; // Construct the SELECT query to retrieve the details based on the selected crop $selectCropQuery = "SELECT Name, Scientific_Name, Family FROM crop WHERE Name = '$selectedCrop' LIMIT 1;"; // Execute the query $cropResult = mysqli_query($conn, $selectCropQuery) or die(mysqli_error($conn)); if (mysqli_num_rows($cropResult) > 0) { $cropRow = mysqli_fetch_assoc($cropResult); echo "<html>"; echo "<head>"; echo "<style>"; echo "body {"; echo " display: flex;"; echo " justify-content: center;"; echo " align-items: center;"; echo " min-height: 100vh;"; echo " background-color: #d3f5a4;"; echo "}"; echo ".container {"; echo " max-width: 1000px;"; echo " background-color: #fff;"; echo " padding: 20px;"; echo " border-radius: 8px;"; echo "}"; echo "</style>"; echo "</head>"; echo "<body>"; echo "<div class='container'>"; echo "<h2> Details of " . $cropRow['Name'] . "</h2>"; echo "<p><strong> Scientific Name of Crop:</strong> " . $cropRow['Scientific_Name'] . "</p>"; echo "<p><strong> Family:</strong> " . $cropRow['Family'] . "</p>"; echo "<h2>Images</h2>"; $selectImagesQuery = "SELECT img FROM crop WHERE Name = '$selectedCrop'"; $imagesResult = mysqli_query($conn, $selectImagesQuery) or die(mysqli_error($conn)); if (mysqli_num_rows($imagesResult) > 0) { $displayedImages = array(); // Array to store displayed image names while ($imageRow = mysqli_fetch_assoc($imagesResult)) { $imageName = $imageRow['img']; if (!in_array($imageName, $displayedImages)) { echo "<img src='images/" . $imageName . "' alt='Crop Image'>"; $displayedImages[] = $imageName; // Add the image name to the displayed images array } } } else { echo "No images found."; } echo "</div>"; echo "</body>"; echo "</html>"; } else { echo "No results found."; } } ?>