// Connect to the MySQL database server $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "flower_shop"; // Create a connection object $conn = new mysqli($servername, $username, $password, $dbname); // Check the connection status if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Get the action parameter from the URL $action = $_GET["action"]; // Switch the action based on the value switch ($action) { // Display the home page with the list of flowers case "home": // Query the database to get all the flowers $sql = "SELECT * FROM flowers"; $result = $conn->query($sql); // Check if the query returned any rows if ($result->num_rows > 0) { // Start the HTML output echo "Flower Shop"; echo "

Welcome to the Flower Shop

"; echo "

Please choose a flower to order:

"; echo ""; echo ""; // Loop through each row in the result set while ($row = $result->fetch_assoc()) { // Get the flower id, name, price, and image from the row $id = $row["id"]; $name = $row["name"]; $price = $row["price"]; $image = $row["image"]; // Display the row as a table row echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } // End the HTML output echo "
NamePriceImageAction
$name$price VNDOrder
"; echo ""; } else { // No rows were returned, display an error message echo "No flowers found in the database."; } break; // Display the order page with the form to enter customer information and quantity case "order": // Get the flower id from the URL $id = $_GET["id"]; // Query the database to get the flower details by id $sql = "SELECT * FROM flowers WHERE id = $id"; $result = $conn->query($sql); // Check if the query returned a row if ($result->num_rows > 0) { // Get the row as an associative array $row = $result->fetch_assoc(); // Get the flower name, price, and image from the row $name = $row["name"]; $price = $row["price"]; $image = $row["image"]; // Start the HTML output echo "Flower Shop - Order"; echo "

Order a Flower

"; echo "

You have chosen to order a $name for $price VND.

"; echo ""; echo "

Please fill in your information and quantity below:

"; // Display a form to enter customer information and quantity echo "
"; echo ""; echo ""; echo "
"; echo ""; echo "
"; echo ""; echo "
"; echo ""; echo "
"; echo ""; echo "
"; // End the HTML output echo ""; } else { // No row was returned, display an error message echo "Invalid flower id."; } break; // Display the confirmation page with the order details and total price case "confirm": // Get the form data from the POST request $id = $_POST["id"]; $name = $_POST["name"]; $address = $_POST["address"]; $phone = $_POST["phone"]; $quantity = $_POST["quantity"]; // Query the database to get the flower details by id $sql = "SELECT * FROM flowers WHERE id = $id"; $result = $conn->query($sql); // Check if the query returned a row if ($result->num_rows > 0) { // Get the row as an associative array $row = $result->fetch_assoc(); // Get the flower name, price, and image from the row $flower_name = $row["name"]; $flower_price = $row["price"]; $flower_image = $row["image"]; // Calculate the total price of the order $total_price = intval($quantity) * intval($flower_price); // Start the HTML output echo "Flower Shop - Confirm"; echo "

Confirm Your Order

"; echo "

You have ordered $quantity $flower_name for $total_price VND.

"; echo ""; echo "

Your information is as follows:

"; // Display the customer information and order details echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
Name$name
Address$address
Phone$phone
Flower$flower_name
Price$flower_price VND
Quantity$quantity
Total$total_price VND
"; // Display a message to thank the customer and confirm the order echo "

Thank you for your order. We will deliver your flower(s) as soon as possible.

"; // End the HTML output echo ""; } else { // No row was returned, display an error message echo "Invalid flower id."; } break; // Display an error message for invalid action default: echo "Invalid action."; }