-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_ewaste.php
More file actions
62 lines (56 loc) · 2.02 KB
/
process_ewaste.php
File metadata and controls
62 lines (56 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
session_start();
require 'connect.php'; // Your database connection file
// Validate seller session
// if (!isset($_SESSION['userType']) !== 'seller') {
// header("Location: login.php");
// exit();
// }
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Sanitize and validate inputs
$seller_id = $_SESSION['Id'];
$ewaste_type = htmlspecialchars($_POST['ewasteType']);
$quantity = filter_var($_POST['quantity'], FILTER_VALIDATE_FLOAT, [
'options' => ['min_range' => 0.1]
]);
$unit = in_array($_POST['unit'], ['pieces', 'kg']) ? $_POST['unit'] : 'pieces';
$contact = preg_replace('/[^0-9]/', '', $_POST['contact']);
$address = htmlspecialchars($_POST['address']);
$notes = !empty($_POST['notes']) ? htmlspecialchars($_POST['notes']) : null;
// Validate required fields
// if (!$quantity || strlen($contact) < 10 || empty($address)) {
// $_SESSION['error'] = "Invalid form data. Please check your inputs.";
// header("Location: seller.php");
// exit();
// }
// Insert into database using prepared statement
try {
$stmt = $conn->prepare("INSERT INTO ewaste_submissions
(seller_id, ewaste_type, quantity, unit, contact, address, notes)
VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("isdssss",
$seller_id,
$ewaste_type,
$quantity,
$unit,
$contact,
$address,
$notes
);
if ($stmt->execute()) {
$_SESSION['success'] = "Submission successful! Your reference ID: " . $stmt->insert_id;
header("Location: s_progress.php");
} else {
throw new Exception("Database error: " . $stmt->error);
}
} catch (Exception $e) {
$_SESSION['error'] = "Submission failed: " . $e->getMessage();
header("Location: seller.php");
} finally {
if (isset($stmt)) $stmt->close();
$conn->close();
}
} else {
header("Location: seller.php");
}
?>