added delete button to editAuction

This commit is contained in:
Joshua Perry 2022-11-20 20:14:56 +00:00
parent 2a819d575e
commit 669791387b
3 changed files with 12 additions and 5 deletions

View File

@ -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;

View File

@ -4,7 +4,6 @@ $stylesheet = '../assets/ibuy.css';
require_once '../../functions.php';
checkListing();
$pdo = startDB();
$listing = getListing();
$pageContent = '<h1>Edit Auction</h1>
@ -14,11 +13,21 @@ $pageContent = '<h1>Edit Auction</h1>
<label>End Date</label> <input name="endDate" type="date"/>
<label>Description</label> <textarea name="description" style="width: 438px; height: 249px;" placeholder="'. $listing['description'] .'"></textarea>
<label>Image</label> <input type="file" name="auctionImg"/>
<label>Delete</label> <input type="checkbox" name="delete" value = "true"/>
<input name="submit" type="submit" value="Submit" style="margin-top: 10px;"/>
</form>';
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 '<script>window.location.href = "../index.php";</script>';
}
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');

View File

@ -1,3 +1 @@
//TODO: upload images
//TODO: Delete auction button on the editAuction page;
//TODO: userReviews, addAdmin, manageAdmin, search