added addAuction.php

This commit is contained in:
Joshua Perry 2022-11-20 14:10:05 +00:00
parent 3f75893a0b
commit 8e497df9b5
4 changed files with 56 additions and 4 deletions

View File

@ -0,0 +1,51 @@
<?php
session_start();
$pageTitle = 'iBuy - Add Auction';
$stylesheet = '../assets/ibuy.css';
if (!isset($_SESSION['loggedin'])) {
echo '<script>window.location.href = "../index.php";</script>';
}
require_once '../../functions.php';
$pdo = startDB();
$pageContent = '<h1>Add auction</h1>
<form action="addAuction.php" method="POST">
<label>Title</label> <input name="title" type="text" placeholder="Auction Title"/>
<label>Category</label> <select name="category" style="width:420px; margin-bottom: 10px;">'. populateCats() .'</select>
<label>End Date</label> <input name="endDate" type="date"/>
<label>Description</label> <textarea name="description" style="width: 438px; height: 249px;" placeholder="description"></textarea>
<input name="submit" type="submit" value="Submit" style="margin-top: 10px;"/>
</form>';
require '../../layout.php';
if (isset($_POST['submit'])) {
$stmt = $pdo->prepare('SELECT * FROM users WHERE user_id = :user_id');
$values = [
'user_id' => $_SESSION['loggedin']
];
$stmt->execute($values);
$user = $stmt->fetch();
$stmt = $pdo->prepare('INSERT INTO auction (title, description, endDate, categoryId, email) VALUES (:title, :description, :endDate, :categoryID, :email)');
$values = [
'title' => $_POST['title'],
'description' => $_POST['description'],
'endDate' => $_POST['endDate'],
'categoryId' => $_POST['category'],
'email' => $user['email']
];
$stmt->execute($values);
echo '<p>Successful Post</p>';
}
function populateCats() {
$cats = fetchCats();
$output = '';
foreach ($cats as &$cat) {
$output .= '<option value="'. $cat['category_id'] .'">'. $cat['name'] .'</option>';
}
return $output;
}

View File

@ -4,7 +4,7 @@ $pageTitle = 'iBuy - Login';
$pageContent = '<p>Don\'t have an account?<a href=\'register.php\'>Click here to register</a></p> $pageContent = '<p>Don\'t have an account?<a href=\'register.php\'>Click here to register</a></p>
<h1>Login</h1> <h1>Login</h1>
<form action="login.php" method="POST"> <form action="login.php" method="POST">
<label>Email</label> <input name="email" type="text" placeholder="john.doe@example.com"/> <label>Email</label> <input name="email" type="email" placeholder="john.doe@example.com"/>
<label>Password</label> <input name="password" type="password" placeholder="password"/> <label>Password</label> <input name="password" type="password" placeholder="password"/>
<input name="submit" type="submit" value="Submit" /> <input name="submit" type="submit" value="Submit" />
</form>'; </form>';

View File

@ -22,8 +22,8 @@ $pageContent = '<p>Already have an account?<a href=\'login.php\'>Click here to L
<form action="register.php" method="POST"> <form action="register.php" method="POST">
<label>First Name</label> <input name="first_name" type="text" placeholder="John"/> <label>First Name</label> <input name="first_name" type="text" placeholder="John"/>
<label>Last Name</label> <input name="last_name" type="text" placeholder="Doe"/> <label>Last Name</label> <input name="last_name" type="text" placeholder="Doe"/>
<label>Email</label> <input name="email" type="text" placeholder="john.doe@example.com"/> <label>Email</label> <input name="email" type="email" placeholder="john.doe@example.com"/>
<label>Password</label> <input name="password" type="text" placeholder="password"/> <label>Password</label> <input name="password" type="password" placeholder="password"/>
<input name="submit" type="submit" value="Submit" /> <input name="submit" type="submit" value="Submit" />
</form>'; </form>';

View File

@ -12,7 +12,8 @@ else {
} }
require_once '../functions.php'; require_once '../functions.php';
$pageContent = '<h1>'.$pageHeading.'</h1> $pageContent = '<a href="account/addAuction.php">post auction</a>
<h1>'.$pageHeading.'</h1>
<ul class="productList">'.populateList($pageHeading).'</ul>'; <ul class="productList">'.populateList($pageHeading).'</ul>';
require '../layout.php'; require '../layout.php';