-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdonate.php
More file actions
59 lines (52 loc) · 2.36 KB
/
Copy pathdonate.php
File metadata and controls
59 lines (52 loc) · 2.36 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
<!DOCTYPE html>
<html>
<head>
<title>Donate</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<?php
include_once('database.php');
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$donorName = trim($_POST['donor_name']);
$userId = $_SESSION['UserID'];
$cityId = $_POST['city'];
$centerId = $_POST['center'];
$donationType = $_POST['donationType'];
$donationDate = $_POST['donationDate'];
try {
$bloodTypeSql = "SELECT BloodType FROM User WHERE UserID = ?";
$bloodTypeStmt = $conn->prepare($bloodTypeSql);
$bloodTypeStmt->bindParam(1, $userId, PDO::PARAM_INT);
$bloodTypeStmt->execute();
$bloodType = $bloodTypeStmt->fetchColumn();
$donationSql = "INSERT INTO Donation (UserID, CenterID, DonationType, DonationDate, DonorName, CityID, BloodType)
VALUES (?, ?, ?, ?, ?, ?, ?)";
$donationStmt = $conn->prepare($donationSql);
$donationStmt->bindParam(1, $userId, PDO::PARAM_INT);
$donationStmt->bindParam(2, $centerId, PDO::PARAM_INT);
$donationStmt->bindParam(3, $donationType, PDO::PARAM_STR);
$donationStmt->bindParam(4, $donationDate, PDO::PARAM_STR);
$donationStmt->bindParam(5, $donorName, PDO::PARAM_STR);
$donationStmt->bindParam(6, $cityId, PDO::PARAM_INT);
$donationStmt->bindParam(7, $bloodType, PDO::PARAM_STR);
$donationStmt->execute();
$donationId = $conn->lastInsertId();
$inventorySql = "INSERT INTO Inventory (DonationId, UserID, CenterID, DonationDate, DonationType, CityID, BloodType)
VALUES (?, ?, ?, ?, ?, ?, ?)";
$inventoryStmt = $conn->prepare($inventorySql);
$inventoryStmt->bindParam(1, $donationId, PDO::PARAM_INT);
$inventoryStmt->bindParam(2, $userId, PDO::PARAM_INT);
$inventoryStmt->bindParam(3, $centerId, PDO::PARAM_INT);
$inventoryStmt->bindParam(4, $donationDate, PDO::PARAM_STR);
$inventoryStmt->bindParam(5, $donationType, PDO::PARAM_STR);
$inventoryStmt->bindParam(6, $cityId, PDO::PARAM_INT);
$inventoryStmt->bindParam(7, $bloodType, PDO::PARAM_STR);
$inventoryStmt->execute();
echo "Registration successful!";
} catch (PDOException $e) {
echo "Error during donation: " . $e->getMessage();
}
}
?>