first commit
This commit is contained in:
109
customers/.hta_slug/edit.php
Normal file
109
customers/.hta_slug/edit.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card shadow-lg">
|
||||
<div class="card-header bg-primary text-white text-center">
|
||||
<h4>Edit Customer Details</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php
|
||||
require('../.hta_config/conf.php');
|
||||
|
||||
try {
|
||||
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Update customer details
|
||||
$stmt = $db->prepare("UPDATE customers SET name = :name, mobile = :mobile, email = :email WHERE customerId = :customerId");
|
||||
$stmt->bindParam(':name', $_POST['name']);
|
||||
$stmt->bindParam(':mobile', $_POST['mobile']);
|
||||
$stmt->bindParam(':email', $_POST['email']);
|
||||
|
||||
$stmt = $db->prepare("SELECT COUNT(*) FROM address WHERE customerId = :customerId");
|
||||
$stmt->bindParam(':customerId', $_POST['customerId']);
|
||||
$stmt->execute();
|
||||
$addressExists = $stmt->fetchColumn();
|
||||
if ($addressExists) {
|
||||
$stmt = $db->prepare("UPDATE address SET city = :city, district = :district, state = :state, pinCode = :pin WHERE customerId = :customerId");
|
||||
} else {
|
||||
$stmt = $db->prepare("INSERT INTO address (customerId, city, district, state, pinCode) VALUES (:customerId, :city, :district, :state, :pin)");
|
||||
}
|
||||
$stmt->bindParam(':city', $_POST['city']);
|
||||
$stmt->bindParam(':district', $_POST['district']);
|
||||
$stmt->bindParam(':state', $_POST['state']);
|
||||
$stmt->bindParam(':pin', $_POST['pinCode']);
|
||||
$stmt->bindParam(':customerId', $_POST['customerId']);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo '<div class="alert alert-success">Customer details updated successfully.</div>';
|
||||
} else {
|
||||
echo '<div class="alert alert-danger">Error updating customer.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch customer data
|
||||
$stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId");
|
||||
$stmt->bindParam(':customerId', $_GET['customerId']);
|
||||
$stmt->execute();
|
||||
$customer = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$stmtAddress = $db->prepare("SELECT * FROM address WHERE customerId = :customerId");
|
||||
$stmtAddress->bindParam(':customerId', $_GET['customerId']);
|
||||
$stmtAddress->execute();
|
||||
$customerAddress = $stmtAddress->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ($customer): ?>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="customerId" value="<?php echo htmlspecialchars($customer['customerId']); ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name">Name:</label>
|
||||
<input type="text" id="name" name="name" class="form-control" value="<?php echo htmlspecialchars($customer['name']); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="mobile">Mobile:</label>
|
||||
<input type="text" id="mobile" name="mobile" class="form-control" value="<?php echo htmlspecialchars($customer['mobile']); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" id="email" name="email" class="form-control" value="<?php echo htmlspecialchars($customer['email']); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="city">City:</label>
|
||||
<input type="text" id="city" name="city" class="form-control" value="<?php echo htmlspecialchars($customerAddress['city'] ?? ''); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="district">District:</label>
|
||||
<input type="text" id="district" name="district" class="form-control" value="<?php echo htmlspecialchars($customerAddress['district'] ?? ''); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="state">State:</label>
|
||||
<input type="text" id="state" name="state" class="form-control" value="<?php echo htmlspecialchars($customerAddress['state'] ?? ''); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="pinCode">Pin Code:</label>
|
||||
<input type="text" id="pinCode" name="pinCode" class="form-control" value="<?php echo htmlspecialchars($customerAddress['pinCode'] ?? ''); ?>" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success btn-block mt-2">Update Customer</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-danger text-center">Customer not found!</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user