// 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 "
Please choose a flower to order:
"; echo "Name | Price | Image | Action |
---|---|---|---|
$name | "; echo "$price VND | "; echo ""; echo " | Order | "; 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 ""; // 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 "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 "Name | $name |
Address | $address |
Phone | $phone |
Flower | $flower_name |
Price | $flower_price VND |
Quantity | $quantity |
Total | $total_price VND |
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."; }