3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Step 1: Connect to the database $conn = new mysqli("localhost", "root", "", "customer_db"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Step 2: Handle form submission if ($_SERVER["REQUEST_METHOD"] == "POST") { $customer_name = $_POST['customer_name']; $email = $_POST['email']; $phone_number = $_POST['phone_number']; $account_type = $_POST['account_type']; $principal = $_POST['principal']; // Calculate interest based on account type $interest = 0; if ($account_type == "Saving") { $interest = $principal * 0.06; // 6% interest } elseif ($account_type == "Fixed Deposit") { $interest = $principal * 0.10; // 10% interest } // Insert data into the database $sql = "INSERT INTO customers (customer_name, email, phone_number, account_type, principal, interest) VALUES ('$customer_name', '$email', '$phone_number', '$account_type', '$principal', '$interest')"; if ($conn->query($sql) === TRUE) { echo "Customer data inserted successfully!"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } ?> <!DOCTYPE html> <html> <head> <title>Customer Management</title> </head> <body> <h1>Customer Management Form</h1> <!-- Step 3: Form to input data --> <form method="POST" action=""> <label>Customer Name:</label> <input type="text" name="customer_name" required><br><br> <label>Email:</label> <input type="email" name="email" required><br><br> <label>Phone Number:</label> <input type="text" name="phone_number" required><br><br> <label>Account Type:</label> <select name="account_type" required> <option value="Saving">Saving</option> <option value="Current">Current</option> <option value="Fixed Deposit">Fixed Deposit</option> </select><br><br> <label>Principal Amount:</label> <input type="number" name="principal" required><br><br> <button type="submit">Submit</button> </form> <h2>Customer Details</h2> <!-- Step 4: Display data --> <?php $sql = "SELECT * FROM customers"; $result = $conn->query($sql); if ($result->num_rows > 0) { echo "<table border='1'> <tr> <th>Customer Name</th> <th>Email</th> <th>Phone Number</th> <th>Account Type</th> <th>Principal</th> <th>Interest</th> </tr>"; while ($row = $result->fetch_assoc()) { echo "<tr> <td>{$row['customer_name']}</td> <td>{$row['email']}</td> <td>{$row['phone_number']}</td> <td>{$row['account_type']}</td> <td>{$row['principal']}</td> <td>{$row['interest']}</td> </tr>"; } echo "</table>"; } else { echo "No customer records found!"; } $conn->close(); ?> </body> </html>
Output for git.master_jit, git.master
Fatal error: Uncaught Error: Class "mysqli" not found in /in/0cJag:3 Stack trace: #0 {main} thrown in /in/0cJag on line 3
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.49 ms | 405 KiB | 5 Q