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"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Item Bill</title> <style> table { width: 60%; border-collapse: collapse; margin: 20px 0; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } </style> </head> <body> <h2>Enter Item Details</h2> <form method="post"> <label for="item_code">Item Codes (comma-separated for 5 items):</label><br> <input type="text" id="item_code" name="item_code" required><br><br> <label for="item_name">Item Names (comma-separated for 5 items):</label><br> <input type="text" id="item_name" name="item_name" required><br><br> <label for="units_sold">Units Sold (comma-separated for 5 items):</label><br> <input type="text" id="units_sold" name="units_sold" required><br><br> <label for="rate">Rates (comma-separated for 5 items):</label><br> <input type="text" id="rate" name="rate" required><br><br> <input type="submit" value="Submit"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // Get input values $item_codes = explode(',', $_POST['item_code']); $item_names = explode(',', $_POST['item_name']); $units_sold = explode(',', $_POST['units_sold']); $rates = explode(',', $_POST['rate']); // Ensure there are exactly 5 items if (count($item_codes) == 5 && count($item_names) == 5 && count($units_sold) == 5 && count($rates) == 5) { echo "<h3>Bill Summary</h3>"; echo "<table>"; echo "<tr><th>Item Code</th><th>Item Name</th><th>Units Sold</th><th>Rate</th><th>Total</th></tr>"; $totalBill = 0; // Loop through the items and display them in a table for ($i = 0; $i < 5; $i++) { $item_code = trim($item_codes[$i]); $item_name = trim($item_names[$i]); $units = intval(trim($units_sold[$i])); $rate = floatval(trim($rates[$i])); $total = $units * $rate; echo "<tr>"; echo "<td>$item_code</td>"; echo "<td>$item_name</td>"; echo "<td>$units</td>"; echo "<td>$rate</td>"; echo "<td>$total</td>"; echo "</tr>"; $totalBill += $total; } echo "<tr><td colspan='4'><strong>Total Bill</strong></td><td><strong>$totalBill</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