PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Bill Form</title> </head> <body> <h2>Enter Item Details</h2> <form method="post" action=""> <label for="item_codes">Item Codes (comma-separated):</label><br> <input type="text" id="item_codes" name="item_codes" required><br><br> <label for="item_names">Item Names (comma-separated):</label><br> <input type="text" id="item_names" name="item_names" required><br><br> <label for="units_sold">Units Sold (comma-separated):</label><br> <input type="text" id="units_sold" name="units_sold" required><br><br> <label for="rates">Rates (comma-separated):</label><br> <input type="text" id="rates" name="rates" required><br><br> <input type="submit" value="Generate Bill"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // Get form input and split each field by commas $item_codes = explode(',', $_POST['item_codes']); $item_names = explode(',', $_POST['item_names']); $units_sold = explode(',', $_POST['units_sold']); $rates = explode(',', $_POST['rates']); // Ensure there are exactly 5 entries for each field if (count($item_codes) == 5 && count($item_names) == 5 && count($units_sold) == 5 && count($rates) == 5) { echo "<h3>Bill Details</h3>"; echo "<table border='1' cellpadding='10' cellspacing='0'>"; echo "<tr><th>Item Code</th><th>Item Name</th><th>Units Sold</th><th>Rate</th><th>Total</th></tr>"; $grand_total = 0; // Display each item in a table row for ($i = 0; $i < 5; $i++) { $total = (float)$units_sold[$i] * (float)$rates[$i]; $grand_total += $total; echo "<tr>"; echo "<td>" . htmlspecialchars($item_codes[$i]) . "</td>"; echo "<td>" . htmlspecialchars($item_names[$i]) . "</td>"; echo "<td>" . htmlspecialchars($units_sold[$i]) . "</td>"; echo "<td>" . htmlspecialchars($rates[$i]) . "</td>"; echo "<td>" . number_format($total, 2) . "</td>"; echo "</tr>"; } echo "<tr><td colspan='4'><strong>Grand Total</strong></td><td><strong>" . number_format($grand_total, 2) . "</strong></td></tr>"; echo "</table>"; } else { echo "<p style='color: red;'>Please enter exactly 5 items for each field.</p>"; } } ?> </body> </html>
Show:  
Copy Clear