updated pdo
This commit is contained in:
parent
3f234df89a
commit
726f927987
|
|
@ -1,10 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
function fetchCats() {
|
function fetchCats() {
|
||||||
$server = 'mysql';
|
$pdo = startDB();
|
||||||
$username = 'student';
|
|
||||||
$password = 'student';
|
|
||||||
$schema = 'assignment1';
|
|
||||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
|
||||||
$stmt = $pdo->prepare('SELECT * FROM category');
|
$stmt = $pdo->prepare('SELECT * FROM category');
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$cats = $stmt->fetchAll();
|
$cats = $stmt->fetchAll();
|
||||||
|
|
@ -22,4 +18,13 @@ function adminCheck() {
|
||||||
echo'<script>window.location.href = "../index.php";</script>';
|
echo'<script>window.location.href = "../index.php";</script>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function startDB() {
|
||||||
|
$server = 'mysql';
|
||||||
|
$username = 'student';
|
||||||
|
$password = 'student';
|
||||||
|
$schema = 'assignment1';
|
||||||
|
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||||
|
return $pdo;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
@ -49,7 +49,7 @@ require_once 'functions.php';
|
||||||
echo $pageContent;
|
echo $pageContent;
|
||||||
?>
|
?>
|
||||||
<footer>
|
<footer>
|
||||||
<a style="text-decoration: none;" href="admin/adminCategories.php">admins</a><br>
|
<a style="text-decoration: none;" href="../admin/adminCategories.php">admins</a><br>
|
||||||
© ibuy <?php echo date('Y')?>
|
© ibuy <?php echo date('Y')?>
|
||||||
</footer>
|
</footer>
|
||||||
</main>
|
</main>
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,9 @@ $pageContent = '<p>Don\'t have an account?<a href=\'register.php\'>Click here to
|
||||||
</form>';
|
</form>';
|
||||||
$stylesheet = '../assets/ibuy.css';
|
$stylesheet = '../assets/ibuy.css';
|
||||||
require '../../layout.php';
|
require '../../layout.php';
|
||||||
|
require_once '../../functions.php';
|
||||||
|
|
||||||
$server = 'mysql';
|
$pdo = startDB();
|
||||||
$username = 'student';
|
|
||||||
$password = 'student';
|
|
||||||
$schema = 'assignment1';
|
|
||||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
|
||||||
|
|
||||||
if (isset($_POST['submit'])) {
|
if (isset($_POST['submit'])) {
|
||||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
|
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
require_once '../../functions.php';
|
||||||
|
|
||||||
function addUser() {
|
function addUser() {
|
||||||
$server = 'mysql';
|
$pdo = startDB();
|
||||||
$username = 'student';
|
|
||||||
$password = 'student';
|
|
||||||
$schema = 'assignment1';
|
|
||||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
|
||||||
|
|
||||||
$stmt = $pdo->prepare('INSERT INTO users (first_name, last_name, email, password, admin)
|
$stmt = $pdo->prepare('INSERT INTO users (first_name, last_name, email, password, admin)
|
||||||
VALUES (:first_name, :last_name, :email, :password, :admin)');
|
VALUES (:first_name, :last_name, :email, :password, :admin)');
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,7 @@ $pageContent = '<h1> Add Category</h1>
|
||||||
require '../../layout.php';
|
require '../../layout.php';
|
||||||
|
|
||||||
if (isset($_POST['submit'])) {
|
if (isset($_POST['submit'])) {
|
||||||
$server = 'mysql';
|
$pdo = startDB();
|
||||||
$username = 'student';
|
|
||||||
$password = 'student';
|
|
||||||
$schema = 'assignment1';
|
|
||||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
|
||||||
$stmt = $pdo->prepare('INSERT INTO category(name)
|
$stmt = $pdo->prepare('INSERT INTO category(name)
|
||||||
VALUES(:name)');
|
VALUES(:name)');
|
||||||
$values = [
|
$values = [
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,7 @@ require_once '../../functions.php';
|
||||||
adminCheck();
|
adminCheck();
|
||||||
|
|
||||||
if (isset($_GET['category_id'])) {
|
if (isset($_GET['category_id'])) {
|
||||||
$server = 'mysql';
|
$pdo = startDB();
|
||||||
$username = 'student';
|
|
||||||
$password = 'student';
|
|
||||||
$schema = 'assignment1';
|
|
||||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
|
||||||
$stmt = $pdo->prepare('DELETE FROM category WHERE category_id= :category_id');
|
$stmt = $pdo->prepare('DELETE FROM category WHERE category_id= :category_id');
|
||||||
$values = [
|
$values = [
|
||||||
'category_id' => $_GET['category_id']
|
'category_id' => $_GET['category_id']
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,7 @@ if (isset($_GET['category_id'])) {
|
||||||
$_SESSION['cat_id'] = $_GET['category_id'];
|
$_SESSION['cat_id'] = $_GET['category_id'];
|
||||||
}
|
}
|
||||||
else if (isset($_POST['submit'])) {
|
else if (isset($_POST['submit'])) {
|
||||||
$server = 'mysql';
|
$pdo = startDB();
|
||||||
$username = 'student';
|
|
||||||
$password = 'student';
|
|
||||||
$schema = 'assignment1';
|
|
||||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
|
||||||
$stmt = $pdo->prepare('UPDATE category SET name= :cat_name WHERE category_id= :category_id');
|
$stmt = $pdo->prepare('UPDATE category SET name= :cat_name WHERE category_id= :category_id');
|
||||||
$values = [
|
$values = [
|
||||||
'cat_name' => $_POST['name'],
|
'cat_name' => $_POST['name'],
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,15 @@ if (isset($_GET['pageHeading'])) {
|
||||||
else {
|
else {
|
||||||
$pageHeading = 'Latest Listings';
|
$pageHeading = 'Latest Listings';
|
||||||
}
|
}
|
||||||
|
require_once '../functions.php';
|
||||||
|
|
||||||
$pageContent = '<h1>'.$pageHeading.'</h1>
|
$pageContent = '<h1>'.$pageHeading.'</h1>
|
||||||
<ul class="productList">'.populateList($pageHeading).'</ul>';
|
<ul class="productList">'.populateList($pageHeading).'</ul>';
|
||||||
require '../layout.php';
|
require '../layout.php';
|
||||||
|
|
||||||
|
|
||||||
function populateList($category) {
|
function populateList($category) {
|
||||||
|
$pdo = startDB();
|
||||||
$output = '';
|
$output = '';
|
||||||
$server = 'mysql';
|
|
||||||
$username = 'student';
|
|
||||||
$password = 'student';
|
|
||||||
$schema = 'assignment1';
|
|
||||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
|
||||||
|
|
||||||
if ($category === 'Latest Listings') {
|
if ($category === 'Latest Listings') {
|
||||||
$stmt = $pdo->prepare('SELECT * FROM auction WHERE endDate > "'. date("Y-m-d H:i:s"). '" ORDER BY endDate DESC');
|
$stmt = $pdo->prepare('SELECT * FROM auction WHERE endDate > "'. date("Y-m-d H:i:s"). '" ORDER BY endDate DESC');
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,11 @@ $pageContent = '<h1>Product Page</h1>
|
||||||
<article class="product">'. populateContent() .'</article>';
|
<article class="product">'. populateContent() .'</article>';
|
||||||
|
|
||||||
require '../layout.php';
|
require '../layout.php';
|
||||||
|
require_once '../functions.php';
|
||||||
|
|
||||||
|
|
||||||
function populateContent() {
|
function populateContent() {
|
||||||
$server = 'mysql';
|
$pdo = startDB();
|
||||||
$username = 'student';
|
|
||||||
$password = 'student';
|
|
||||||
$schema = 'assignment1';
|
|
||||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
|
||||||
|
|
||||||
$stmt = $pdo->prepare('SELECT * FROM auction WHERE listing_id= :listing_id');
|
$stmt = $pdo->prepare('SELECT * FROM auction WHERE listing_id= :listing_id');
|
||||||
$values = [
|
$values = [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue