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