added delete button to editAuction
This commit is contained in:
parent
2a819d575e
commit
669791387b
|
|
@ -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';
|
$server = 'mysql';
|
||||||
$username = 'student';
|
$username = 'student';
|
||||||
$password = 'student';
|
$password = 'student';
|
||||||
|
|
@ -84,7 +84,7 @@ function getFirstAllMatches($tableName, $constraintCol, $constraint) {
|
||||||
return executeAllQuery($tableName, $constraintCol, $constraint)->fetch();
|
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/';
|
$imgDir = 'public/images/auctions/';
|
||||||
$file = $imgDir . $name;
|
$file = $imgDir . $name;
|
||||||
$okFlag = true;
|
$okFlag = true;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ $stylesheet = '../assets/ibuy.css';
|
||||||
require_once '../../functions.php';
|
require_once '../../functions.php';
|
||||||
|
|
||||||
checkListing();
|
checkListing();
|
||||||
$pdo = startDB();
|
|
||||||
$listing = getListing();
|
$listing = getListing();
|
||||||
|
|
||||||
$pageContent = '<h1>Edit Auction</h1>
|
$pageContent = '<h1>Edit Auction</h1>
|
||||||
|
|
@ -14,11 +13,21 @@ $pageContent = '<h1>Edit Auction</h1>
|
||||||
<label>End Date</label> <input name="endDate" type="date"/>
|
<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>Description</label> <textarea name="description" style="width: 438px; height: 249px;" placeholder="'. $listing['description'] .'"></textarea>
|
||||||
<label>Image</label> <input type="file" name="auctionImg"/>
|
<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;"/>
|
<input name="submit" type="submit" value="Submit" style="margin-top: 10px;"/>
|
||||||
</form>';
|
</form>';
|
||||||
require '../../layout.php';
|
require '../../layout.php';
|
||||||
|
|
||||||
if(isset($_POST['submit'])) {
|
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'])) {
|
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');
|
$stmt = $pdo->prepare('UPDATE auction SET title = :title, categoryId = :categoryId, endDate = :endDate, description = :description, imgUrl = :imgUrl WHERE listing_id = :listing_id');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue