Skip to main content
Sign in
Snippets Groups Projects
Commit 7f86495d authored by vanessrw's avatar vanessrw
Browse files

CRUD: gambar

parent 5321acf5
No related branches found
No related tags found
No related merge requests found
......@@ -11,16 +11,18 @@ class EventController {
$this->eventModel = new EventModel();
}
public function createEvent($stock, $createdTime, $details) {
return $this->eventModel->createEvent($stock, $createdTime, $details);
public function createEvent($stock, $createdTime, $details, $gambar) {
$eventModel = new EventModel();
$eventModel->createEvent($stock, $createdTime, $details, $gambar);
}
public function getEvent($eventId) {
return $this->eventModel->getEvent($eventId);
}
public function updateEvent($eventId, $stock, $createdTime, $details) {
return $this->eventModel->updateEvent($eventId, $stock, $createdTime, $details);
public function updateEvent($eventId, $stock, $createdTime, $details, $gambar) {
$eventModel = new EventModel();
$eventModel->updateEvent($eventId, $stock, $createdTime, $details, $gambar);
}
public function deleteEvent($eventId) {
......
......
<?php
require_once(__DIR__ . '/../../db/connect.php');
require_once(__DIR__ . '/../../util.php');
class EventModel {
public function createEvent($stock, $createdTime, $details) {
public function createEvent($stock, $createdTime, $details, $gambar) {
echo "createEvent method called<br>";
global $db;
$stmt = $db->prepare("INSERT INTO events (event_stock, event_created_time, event_details) VALUES (?, ?, ?)");
// Check if a file is uploaded
if ($gambar !== null && isset($gambar['name']) && isset($gambar['tmp_name'])) {
$uploadDirectory = __DIR__ . '/../../assets/';
$uploadedFilePath = $uploadDirectory . $gambar['name'];
if ($stmt->execute([$stock, $createdTime, $details])) {
echo "Event created successfully";
// Move the uploaded file to the desired directory
if (move_uploaded_file($gambar['tmp_name'], $uploadedFilePath)) {
echo "File uploaded successfully<br>";
} else {
echo "Error creating event: " . print_r($stmt->errorInfo(), true);
echo "Error moving file to destination<br>";
$uploadedFilePath = null; // Set to null if there's an error
}
} else {
echo "No file uploaded<br>";
$uploadedFilePath = null; // Set to null if no file is uploaded
}
$stmt = $db->prepare("INSERT INTO events (event_stock, event_created_time, event_details, gambar) VALUES (?, ?, ?, ?)");
public function getEvent($eventId) {
global $db;
$stmt = $db->prepare("SELECT * FROM events WHERE event_id = ?");
$stmt->execute([$eventId]);
return $stmt->fetch(PDO::FETCH_ASSOC);
if ($stmt->execute([$stock, $createdTime, $details, $uploadedFilePath])) {
echo "Event created successfully";
} else {
echo "Error creating event: " . print_r($stmt->errorInfo(), true);
}
}
public function updateEvent($eventId, $stock, $createdTime, $details) {
public function updateEvent($eventId, $stock, $createdTime, $details, $gambar = null) {
global $db;
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 1);
echo "Updating Event with ID: $eventId, Stock: $stock, Created Time: $createdTime, Details: $details";
// Check whether a new image is provided
if ($gambar !== null) {
$sql = "UPDATE events SET event_stock = '$stock', event_created_time = '$createdTime', event_details = '$details', gambar = '$gambar' WHERE event_id = $eventId";
} else {
$sql = "UPDATE events SET event_stock = '$stock', event_created_time = '$createdTime', event_details = '$details' WHERE event_id = $eventId";
}
$rowCount = $db->exec($sql);
......@@ -41,10 +56,10 @@ class EventModel {
} else {
echo "Error updating event: " . print_r($db->errorInfo(), true);
}
return "Event updated successfully";
}
public function deleteEvent($eventId) {
global $db;
......@@ -71,8 +86,6 @@ class EventModel {
}
}
public function getAllEvents() {
global $db;
......
......
assets/1.jpg

42.7 KiB

assets/10.jpg

55.1 KiB

assets/11.png

15 KiB

assets/12.jpg

99.9 KiB

assets/13.jpg

150 KiB

assets/14.jpg

1.26 MiB

assets/15.jpg

344 KiB

assets/16.jpg

51.8 KiB

assets/2.png

182 KiB

assets/3.jpg

31.5 KiB

assets/4.jpg

234 KiB

assets/5.jpg

36.8 KiB

assets/6.png

3.44 KiB

assets/7.jpeg

69.2 KiB

assets/8.png

790 KiB

assets/9.jpg

45.2 KiB

assets/ramen.jpg

58.4 KiB

......@@ -5,12 +5,12 @@
if (isset($db)) {
try {
$sqlEvent = <<<EOF
INSERT INTO events (event_stock, event_created_time, event_details) VALUES
(100, '2023-09-30 10:00:00', 'Music Concert'),
(50, '2023-10-05 15:30:00', 'Art Exhibition'),
(200, '2023-11-12 18:45:00', 'Sports Tournament'),
(75, '2023-12-03 20:00:00', 'Comedy Show'),
(120, '2024-01-18 14:15:00', 'Tech Conference');
INSERT INTO events (event_stock, event_created_time, event_details, gambar) VALUES
(100, '2023-09-30 10:00:00', 'Music Concert', 'assets/1.jpg'),
(50, '2023-10-05 15:30:00', 'Art Exhibition', 'assets/2.jpg'),
(200, '2023-11-12 18:45:00', 'Sports Tournament', 'assets/3.jpg'),
(75, '2023-12-03 20:00:00', 'Comedy Show', 'assets/4.jpg'),
(120, '2024-01-18 14:15:00', 'Tech Conference', 'assets/5.jpg');
EOF;
$sqlTicket = <<<EOF
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment