diff --git a/.env b/.env index 82c3514..e0a84b3 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ DB_HOST=127.0.0.1 DB_PORT=3306 -DB_DATABASE=local_db +DB_DATABASE=app DB_USERNAME=root -DB_PASSWORD=password +DB_PASSWORD=password \ No newline at end of file diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 0000000..eada832 --- /dev/null +++ b/admin/index.php @@ -0,0 +1,47 @@ +query('SELECT * FROM leads'); +$leads = $stmt->fetchAll(); + +?> + + + + + + Admin Dashboard + + +

Admin Dashboard

+

Welcome to the admin dashboard.

+

Logout

+ +

Leads

+ + + + + + + + + + + + + + + + + + + +
IDNameEmailCreated At
+ + diff --git a/admin/login.php b/admin/login.php new file mode 100644 index 0000000..476fab2 --- /dev/null +++ b/admin/login.php @@ -0,0 +1,67 @@ + + + + + + + Admin Login + + + +
+
+
+
+
+

Admin Login

+
+
+ +
+ +
+
+ + +
+
+ + +
+
+ +
+
+
+

Don't have an account? Register here

+
+
+
+
+
+
+ + diff --git a/admin/logout.php b/admin/logout.php new file mode 100644 index 0000000..f57c682 --- /dev/null +++ b/admin/logout.php @@ -0,0 +1,6 @@ + response.json()) + .then(data => { + if (data.success) { + form.reset(); + formStatus.innerHTML = '
' + data.message + '
'; + } else { + formStatus.innerHTML = '
' + data.error + '
'; + } + }) + .catch(error => { + formStatus.innerHTML = '
An error occurred. Please try again later.
'; + }); +}); diff --git a/contact.php b/contact.php new file mode 100644 index 0000000..dd23c4c --- /dev/null +++ b/contact.php @@ -0,0 +1,78 @@ + + + + + + + Contact Us + + + + +
+
+ +
+
+ +
+
+
+

Contact Us

+

We'd love to hear from you. Please fill out the form below.

+
+
+ +
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+ + + + + + diff --git a/contact_handler.php b/contact_handler.php index db563dd..0f00477 100644 --- a/contact_handler.php +++ b/contact_handler.php @@ -1,4 +1,5 @@ + + + + + + Dashboard + + + + +
+
+
+

Welcome, !

+

This is your dashboard.

+
+
+
+ + diff --git a/db/config.php b/db/config.php index 6723641..5a81c33 100644 --- a/db/config.php +++ b/db/config.php @@ -2,7 +2,7 @@ require_once __DIR__ . '/../lib.php'; -load_env(__DIR__ . '/../.env'); +$_ENV = array_merge($_ENV, load_env(__DIR__ . '/../.env')); function db(): ?PDO { @@ -12,11 +12,11 @@ function db(): ?PDO return $pdo; } - $host = getenv('DB_HOST'); - $port = getenv('DB_PORT'); - $db = getenv('DB_DATABASE'); - $user = getenv('DB_USERNAME'); - $pass = getenv('DB_PASSWORD'); + $host = $_ENV['DB_HOST'] ?? null; + $port = $_ENV['DB_PORT'] ?? null; + $db = $_ENV['DB_DATABASE'] ?? null; + $user = $_ENV['DB_USERNAME'] ?? null; + $pass = $_ENV['DB_PASSWORD'] ?? null; if (!$host || !$db || !$user) { // You could log an error or throw an exception here @@ -37,7 +37,6 @@ function db(): ?PDO } catch (PDOException $e) { // In a real application, you'd log this error and show a generic error page. // For development, it's okay to show the error. - // throw new PDOException($e->getMessage(), (int)$e->getCode()); error_log('DB Connection Error: ' . $e->getMessage()); return null; } diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..04f9e75 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,22 @@ +exec($sql); + } catch (PDOException $e) { + echo "Error running migration: " . $e->getMessage() . "\n"; + // You might want to log this or handle it more gracefully + } + } +} + +run_migrations(); \ No newline at end of file diff --git a/db/migrations/002_create_users_table.sql b/db/migrations/002_create_users_table.sql new file mode 100644 index 0000000..7c2d022 --- /dev/null +++ b/db/migrations/002_create_users_table.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS `users` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `username` VARCHAR(255) NOT NULL UNIQUE, + `password` VARCHAR(255) NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); \ No newline at end of file diff --git a/db/migrations/003_add_name_and_email_to_users.sql b/db/migrations/003_add_name_and_email_to_users.sql new file mode 100644 index 0000000..d646411 --- /dev/null +++ b/db/migrations/003_add_name_and_email_to_users.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN name VARCHAR(255) NOT NULL, ADD COLUMN email VARCHAR(255) NOT NULL UNIQUE; \ No newline at end of file diff --git a/db/seed.php b/db/seed.php new file mode 100644 index 0000000..5007b7f --- /dev/null +++ b/db/seed.php @@ -0,0 +1,24 @@ +prepare("INSERT INTO users (username, password) VALUES (?, ?)"); + try { + $stmt->execute([$username, $password]); + echo "Admin user created successfully.\n"; + } catch (PDOException $e) { + if ($e->errorInfo[1] == 1062) { + echo "Admin user already exists.\n"; + } else { + echo "Error creating admin user: " . $e->getMessage() . "\n"; + } + } +} + +seed_users(); + diff --git a/index.php b/index.php index e3a7157..92c5cb0 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,4 @@ + @@ -28,7 +29,7 @@