From 016ea4bb545385a03ee6fec2a1886dd726a8dc81 Mon Sep 17 00:00:00 2001 From: Marcel Peterkau Date: Sun, 18 Sep 2022 22:53:41 +0200 Subject: [PATCH] Add Item and Download of Images works --- add_item.php | 56 ++++++++++++++++++++++++++++++++++++++ include/listgenerator.php | 14 ++++++---- index.php | 57 +++++++++++++++++++++++++++++++++++---- 3 files changed, 117 insertions(+), 10 deletions(-) create mode 100644 add_item.php diff --git a/add_item.php b/add_item.php new file mode 100644 index 0000000..ac25236 --- /dev/null +++ b/add_item.php @@ -0,0 +1,56 @@ +connect_error) { + die('Connection failed: ' . $conn->connect_error); +} + +$stmt = $conn->prepare('INSERT INTO whishes (title, description, link, image, price) VALUES (?, ?, ?, ?, ?)'); + +if (false === $stmt) { + die('prepare() failed: ' . htmlspecialchars($mysqli->error)); +} + +$rc = $stmt->bind_param('ssssi', $ItemTitle, $ItemDescription, $imageLocalLink, $ItemImage, $ItemPriceCents); +if (false === $rc) { + die('bind_param() failed: ' . htmlspecialchars($stmt->error)); +} + +$rc = $stmt->execute(); +if (false === $rc) { + die('execute() failed: ' . htmlspecialchars($stmt->error)); +} + +$stmt->close(); +$conn->close(); + +header('Location: ' . $_SERVER['HTTP_REFERER']); diff --git a/include/listgenerator.php b/include/listgenerator.php index 6a0eaa7..08744d1 100644 --- a/include/listgenerator.php +++ b/include/listgenerator.php @@ -1,10 +1,14 @@
@@ -13,8 +17,8 @@ function generateListItem($ListItemID, $ItemImage, $ItemTitle, $ItemPrice, $Item

' . $ItemComment . '

- - + zum Anbieter +
' . $formatter->formatCurrency($ItemPrice / 100, 'EUR') . '
diff --git a/index.php b/index.php index 7adb115..9fcf14e 100644 --- a/index.php +++ b/index.php @@ -60,14 +60,14 @@ include_once('config/config.php'); // Check connection if ($conn->connect_error) { - die("Connection failed: " . $conn->connect_error); + die('Connection failed: ' . $conn->connect_error); } - $sql = "SELECT ID, title, description, image, reserved, price FROM whishes"; + $sql = 'SELECT ID, title, description, link, image, reserved, price FROM whishes'; $result = $conn->query($sql); if ($result !== false && $result->num_rows > 0) { while ($row = $result->fetch_assoc()) { - generateListItem($row['ID'], $row['image'], $row['title'], $row['price'], $row['description']); + generateListItem($row['ID'], $row['image'], $row['title'], $row['link'], $row['price'], $row['description'], $row['reserved']); } $conn->close(); } @@ -108,7 +108,7 @@ include_once('config/config.php');
- + + + + +