From 11336c0d335be681ff97ab6a974b04973dd79fb3 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 5 Nov 2025 08:05:56 +0000 Subject: [PATCH] database --- dashboard.php | 62 +++++++++++++++++++++++ db/config.php | 51 +++++++++++++------ index.php | 135 +++++++++++++++++++++++++++----------------------- login.php | 112 +++++++++++++++++++++++++++++++++++++++++ logout.php | 21 ++++++++ register.php | 107 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 411 insertions(+), 77 deletions(-) create mode 100644 dashboard.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 register.php diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..6f10d70 --- /dev/null +++ b/dashboard.php @@ -0,0 +1,62 @@ + + + + + + + Dashboard - E-Waste Reclaimer + + + + +
+ +
+ +
+
+

Welcome, !

+

This is your dashboard. From here you will be able to submit e-waste, track your points, and see your submission history.

+ +
+
+

Your Points

+

0

+

Keep recycling to earn more!

+
+
+

Submissions

+

0

+ Submit New E-Waste +
+
+
+
+ + + + diff --git a/db/config.php b/db/config.php index 8a6cef6..8ab4362 100644 --- a/db/config.php +++ b/db/config.php @@ -6,18 +6,41 @@ define('DB_USER', 'app_31009'); define('DB_PASS', '2c66b530-2a65-423a-a106-6760b49ad1a2'); function db() { - static $pdo; - if (!$pdo) { - $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [ - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - $pdo->exec('CREATE TABLE IF NOT EXISTS centers ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) NOT NULL, - address VARCHAR(255) NOT NULL, - contact VARCHAR(255) NOT NULL - );'); - } - return $pdo; + static $pdo; + if (!$pdo) { + try { + // Connect without specifying a database + $pdo = new PDO('mysql:host='.DB_HOST.';charset=utf8mb4', DB_USER, DB_PASS, [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ]); + + // Create the database if it doesn't exist + $pdo->exec('CREATE DATABASE IF NOT EXISTS '.DB_NAME); + // Select the database + $pdo->exec('USE '.DB_NAME); + + $pdo->exec('CREATE TABLE IF NOT EXISTS centers ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + address VARCHAR(255) NOT NULL, + contact VARCHAR(255) NOT NULL + );'); + + $pdo->exec("CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + role ENUM('guest', 'user', 'center_staff', 'admin') NOT NULL DEFAULT 'user', + points INT DEFAULT 0, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + );"); + } catch (PDOException $e) { + error_log('Database setup failed: ' . $e->getMessage()); + // You could display a generic error page here instead of dying + die('Database setup failed. Please check the logs.'); + } + } + return $pdo; } diff --git a/index.php b/index.php index 8b7bf64..089ef76 100644 --- a/index.php +++ b/index.php @@ -1,84 +1,93 @@ + E-Waste Reclaimer - - - - - - - - - - + + + - - -
-
- - E-Waste Reclaimer - -
- Login - Register + +
+
-
-
-

Find a Recycling Center

-

Help the planet by responsibly disposing of your electronic waste.

-
+
+
+

Welcome to E-Waste Reclaimer

+

Your partner in responsible electronics recycling. Find a center near you and help us build a sustainable future.

+ Find a Center +
-
+
+

Recycling Centers

+
'GreenTech Recyclers', - 'address' => '123 Eco Lane, Green City, 12345', - 'contact' => 'contact@greentech.com' - ], - [ - 'name' => 'Circuit Savers', - 'address' => '456 Recycle Ave, Tech Town, 67890', - 'contact' => 'info@circuitsavers.com' - ], - [ - 'name' => 'Eco-Warriors', - 'address' => '789 Planet Blvd, Nature Village, 11223', - 'contact' => 'support@ecowarriors.org' - ] - ]; + try { + $pdo = db(); + + $stmt = $pdo->query("SELECT COUNT(*) FROM centers"); + if ($stmt->fetchColumn() == 0) { + $sample_centers = [ + ['name' => 'GreenTech Recyclers', 'address' => '123 Eco Lane, Green City', 'contact' => 'contact@greentech.com'], + ['name' => 'Circuit Savers', 'address' => '456 Recycle Ave, Tech Town', 'contact' => 'info@circuitsavers.com'], + ['name' => 'Eco-Warriors', 'address' => '789 Planet Blvd, Nature Village', 'contact' => 'support@ecowarriors.org'] + ]; + + $insert_stmt = $pdo->prepare("INSERT INTO centers (name, address, contact) VALUES (:name, :address, :contact)"); + foreach ($sample_centers as $center) { + $insert_stmt->execute($center); + } + } - foreach ($centers as $center): ?> -
-
-
-
-

- -

-

- -

-
+ $centers = $pdo->query("SELECT * FROM centers ORDER BY name")->fetchAll(); + + } catch (PDOException $e) { + $centers = []; + error_log("Database error: " . $e->getMessage()); + } + + if (!empty($centers)): + foreach ($centers as $center): ?> +
+
+

+

+

-
- -
+ +
No recycling centers found. Please check back later.
+ +
+
-