diff --git a/functions.php b/functions.php index 0004ba5..e7a5cd7 100644 --- a/functions.php +++ b/functions.php @@ -19,7 +19,7 @@ function adminCheck() { } } -function startDB() { +function startDB() { // Code for connecting to the database from https://www.sitepoint.com/re-introducing-pdo-the-right-way-to-access-databases-in-php/ $server = 'mysql'; $username = 'student'; $password = 'student'; @@ -84,7 +84,7 @@ function getFirstAllMatches($tableName, $constraintCol, $constraint) { return executeAllQuery($tableName, $constraintCol, $constraint)->fetch(); } -function imageUpload($name) { +function imageUpload($name) { //Code for uploading an image. Modified from https://www.w3schools.com/php/php_file_upload.asp $imgDir = 'public/images/auctions/'; $file = $imgDir . $name; $okFlag = true; diff --git a/public/account/editAuction.php b/public/account/editAuction.php index 0dbffc0..99a7962 100644 --- a/public/account/editAuction.php +++ b/public/account/editAuction.php @@ -4,7 +4,6 @@ $stylesheet = '../assets/ibuy.css'; require_once '../../functions.php'; checkListing(); -$pdo = startDB(); $listing = getListing(); $pageContent = '

Edit Auction

@@ -14,11 +13,21 @@ $pageContent = '

Edit Auction

+ '; require '../../layout.php'; if(isset($_POST['submit'])) { + $pdo = startDB(); + if(isset($_POST['delete'])) { + $stmt = $pdo->prepare('DELETE FROM auction WHERE listing_id = :listing_id'); + $values = [ + 'listing_id' => $listing['listing_id'] + ]; + $stmt->execute($values); + echo ''; + } if(imageUpload($_POST['title'].$_POST['endDate'])) { $stmt = $pdo->prepare('UPDATE auction SET title = :title, categoryId = :categoryId, endDate = :endDate, description = :description, imgUrl = :imgUrl WHERE listing_id = :listing_id'); diff --git a/todo.txt b/todo.txt index 8827b91..29fb0f8 100644 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1 @@ -//TODO: upload images -//TODO: Delete auction button on the editAuction page; //TODO: userReviews, addAdmin, manageAdmin, search \ No newline at end of file