@ 2024-11-30T02:35:59Z <?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>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.4.2 0.016 0.007 21.27 8.4.1 0.036 0.013 17.47 8.3.15 0.010 0.010 17.25 8.3.14 0.035 0.010 16.57 8.3.13 0.030 0.006 16.71 8.3.12 0.027 0.008 16.69 8.3.11 0.030 0.011 16.61 8.3.10 0.033 0.013 16.84 8.3.9 0.034 0.011 16.55 8.3.8 0.034 0.007 16.48 8.3.7 0.038 0.007 16.52 8.3.6 0.039 0.006 16.68 8.3.5 0.039 0.006 16.62 8.3.4 0.039 0.007 17.29 8.3.3 0.029 0.003 17.50 8.3.2 0.031 0.006 17.46 8.3.1 0.019 0.011 17.55 8.3.0 0.012 0.006 17.64 8.2.27 0.015 0.004 16.57 8.2.26 0.018 0.014 16.60 8.2.25 0.025 0.013 16.56 8.2.24 0.032 0.003 16.61 8.2.23 0.034 0.004 16.51 8.2.22 0.028 0.006 16.62 8.2.21 0.023 0.010 16.69 8.2.20 0.026 0.006 16.66 8.2.19 0.024 0.007 16.73 8.2.18 0.026 0.013 16.61 8.2.17 0.032 0.009 17.52 8.2.16 0.029 0.007 17.70 8.2.15 0.017 0.017 17.31 8.2.14 0.034 0.004 17.41 8.2.13 0.030 0.010 17.27 8.2.12 0.026 0.015 17.58 8.2.11 0.038 0.003 17.18 8.2.10 0.030 0.013 17.48 8.2.9 0.041 0.004 17.54 8.2.8 0.031 0.007 17.36 8.2.7 0.023 0.008 17.24 8.2.6 0.018 0.011 17.47 8.2.5 0.011 0.007 17.58 8.2.4 0.021 0.011 17.21 8.2.3 0.011 0.008 17.54 8.2.2 0.017 0.005 17.46 8.2.1 0.021 0.004 17.51 8.2.0 0.028 0.006 17.03
preferences:dark mode live preview
27.21 ms | 403 KiB | 5 Q