printer-repair-royalty / delete_record.php
Ripcurlsurf's picture
can this be written in php and use an sql for its database
ff9ae2f verified
```php
<?php
$id = $_GET['id'] ?? 0;
try {
$conn = new PDO("mysql:host=localhost;dbname=bhbm_service", "username", "password");
$stmt = $conn->prepare("DELETE FROM service_records WHERE id = ?");
$stmt->execute([$id]);
header("Location: service_records.php");
exit();
} catch(PDOException $e) {
die("Database error: " . $e->getMessage());
}
?>
```
You'll also need to create these database tables:
```sql
CREATE DATABASE bhbm_service;
CREATE TABLE service_records (
id INT AUTO_INCREMENT PRIMARY KEY,
client_name VARCHAR(100) NOT NULL,
contact_number VARCHAR(20) NOT NULL,
equipment_type VARCHAR(50) NOT NULL,
brand VARCHAR(50) NOT NULL,
serial_number VARCHAR(50),
issue_description TEXT NOT NULL,
service_date DATE NOT NULL,
technician VARCHAR(50) NOT NULL,
service_notes TEXT,
status VARCHAR(20) DEFAULT 'Completed',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE service_requests (
id INT AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(100) NOT NULL,
customer_email VARCHAR(100) NOT NULL,
customer_phone VARCHAR(20) NOT NULL,
customer_company VARCHAR(100),
equipment_type VARCHAR(50) NOT NULL,
brand VARCHAR(50) NOT NULL,
model VARCHAR(50),
issue_description TEXT NOT NULL,
contact_method VARCHAR(20) NOT NULL,
status VARCHAR(20) DEFAULT 'New',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```