From df71b56319e24ca68e2653de4decddf6b39aecb8 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 4 Sep 2025 13:24:51 +0000 Subject: [PATCH] main --- add_pet.php | 104 ++++++++++++++++++++++++++++++ css/style.css | 32 ++++++++++ db/config.php | 17 +++++ index.php | 174 ++++++++++++++++++++------------------------------ js/script.js | 38 +++++++++++ login.php | 85 ++++++++++++++++++++++++ logout.php | 10 +++ my_pets.php | 88 +++++++++++++++++++++++++ register.php | 71 ++++++++++++++++++++ setup.php | 34 ++++++++++ 10 files changed, 547 insertions(+), 106 deletions(-) create mode 100644 add_pet.php create mode 100644 css/style.css create mode 100644 db/config.php create mode 100644 js/script.js create mode 100644 login.php create mode 100644 logout.php create mode 100644 my_pets.php create mode 100644 register.php create mode 100644 setup.php diff --git a/add_pet.php b/add_pet.php new file mode 100644 index 0000000..0d0ea18 --- /dev/null +++ b/add_pet.php @@ -0,0 +1,104 @@ +prepare($sql); + + $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); + $stmt->bindParam(':name', $name, PDO::PARAM_STR); + $stmt->bindParam(':age', $age, PDO::PARAM_INT); + $stmt->bindParam(':breed', $breed, PDO::PARAM_STR); + $stmt->bindParam(':photo_url', $photo_url, PDO::PARAM_STR); + + if ($stmt->execute()) { + $success = "Pet added successfully!"; + } else { + $error = "Something went wrong. Please try again later."; + } + } catch (PDOException $e) { + $error = "Error: " . $e->getMessage(); + } + $conn = null; + } +} +?> + + + + + + + Add Pet - Pet Tinder + + + + + +
+

Add a New Pet

+ +
+ + +
+ +
" method="post" class="mt-4"> +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ + \ No newline at end of file diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..1f8012a --- /dev/null +++ b/css/style.css @@ -0,0 +1,32 @@ +body { + background-color: #f8f9fa; +} + +#pet-card { + border-radius: 15px; + overflow: hidden; + height: 70vh; + display: flex; + flex-direction: column; +} + +.card-img-top { + width: 100%; + height: 75%; + object-fit: cover; +} + +.card-body { + flex-grow: 1; +} + +#actions .btn { + width: 100px; + height: 100px; + border-radius: 50%; + margin: 0 20px; + font-size: 1.5rem; + display: inline-flex; + align-items: center; + justify-content: center; +} diff --git a/db/config.php b/db/config.php new file mode 100644 index 0000000..1874868 --- /dev/null +++ b/db/config.php @@ -0,0 +1,17 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ]); + } + return $pdo; +} diff --git a/index.php b/index.php index 9d8f280..f1b54f1 100644 --- a/index.php +++ b/index.php @@ -1,115 +1,77 @@ query($sql); + $pets = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + // Don't display error to user, just log it or handle it +} -$phpVersion = PHP_VERSION; -$now = date('Y-m-d H:i:s'); ?> - - + + - - - New Style - - - - + + + + Tinder for Pets + + -
-
-

Welcome!

-

Your project is ready to conquer the peaks.

-

PHP version:

+ + +
+
+
+
+ +
+
+ + +
+
+
-
- + + + + \ No newline at end of file diff --git a/js/script.js b/js/script.js new file mode 100644 index 0000000..c0f484a --- /dev/null +++ b/js/script.js @@ -0,0 +1,38 @@ +document.addEventListener('DOMContentLoaded', () => { + const petCard = document.getElementById('pet-card'); + const likeBtn = document.getElementById('like-btn'); + const dislikeBtn = document.getElementById('dislike-btn'); + + + + let currentPetIndex = 0; + + function renderPet() { + if (currentPetIndex >= pets.length) { + petCard.innerHTML = `
Больше питомцев нет!
`; + likeBtn.disabled = true; + dislikeBtn.disabled = true; + return; + } + + const pet = pets[currentPetIndex]; + petCard.innerHTML = ` + ${pet.name} +
+
${pet.name}
+

Возраст: ${pet.age}

+

Порода: ${pet.breed}

+
+ `; + } + + function showNextPet() { + currentPetIndex++; + renderPet(); + } + + likeBtn.addEventListener('click', showNextPet); + dislikeBtn.addEventListener('click', showNextPet); + + renderPet(); +}); diff --git a/login.php b/login.php new file mode 100644 index 0000000..017fc2a --- /dev/null +++ b/login.php @@ -0,0 +1,85 @@ +prepare($sql); + $stmt->bindParam(':username', $username, PDO::PARAM_STR); + + if ($stmt->execute()) { + if ($stmt->rowCount() == 1) { + $row = $stmt->fetch(); + $id = $row['id']; + $hashed_password = $row['password']; + if (password_verify($password, $hashed_password)) { + session_start(); + $_SESSION["loggedin"] = true; + $_SESSION["id"] = $id; + $_SESSION["username"] = $username; + header("location: index.php"); + } else { + $error = 'The password you entered was not valid.'; + } + } else { + $error = 'No account found with that username.'; + } + } else { + $error = "Oops! Something went wrong. Please try again later."; + } + } catch (PDOException $e) { + $error = "Error: " . $e->getMessage(); + } + $conn = null; + } +} +?> + + + + + + + Login - Pet Tinder + + + + +
+

Login

+ +
+ +
" method="post" class="mt-4"> +
+ + +
+
+ + +
+
+ +
+

Don't have an account? Sign up now.

+
+
+ + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..4ab8069 --- /dev/null +++ b/logout.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/my_pets.php b/my_pets.php new file mode 100644 index 0000000..d28e1f0 --- /dev/null +++ b/my_pets.php @@ -0,0 +1,88 @@ +prepare("SELECT * FROM pets WHERE user_id = ? ORDER BY created_at DESC"); +$stmt->execute([$user_id]); +$pets = $stmt->fetchAll(); + +?> + + + + + + + My Pets + + + + + + + +
+

My Pets

+
+ +
+

You haven't added any pets yet. Add one now!

+
+ + +
+
+ <?= htmlspecialchars($pet['name']) ?> +
+
+

+ Breed:
+ Age: +

+
+
+
+ + +
+
+ + + + diff --git a/register.php b/register.php new file mode 100644 index 0000000..020b774 --- /dev/null +++ b/register.php @@ -0,0 +1,71 @@ +prepare($sql); + + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + + $stmt->bindParam(':username', $username); + $stmt->bindParam(':password', $hashed_password); + + if ($stmt->execute()) { + header("location: login.php"); + } else { + $error = "Something went wrong. Please try again later."; + } + } catch (PDOException $e) { + if ($e->errorInfo[1] == 1062) { // Duplicate entry + $error = "This username is already taken."; + } else { + $error = "Error: " . $e->getMessage(); + } + } + $conn = null; + } +} +?> + + + + + + Register - Pet Tinder + + + + +
+

Register

+ +
+ +
" method="post" class="mt-4"> +
+ + +
+
+ + +
+
+ +
+

Already have an account? Login here.

+
+
+ + \ No newline at end of file diff --git a/setup.php b/setup.php new file mode 100644 index 0000000..5e26d44 --- /dev/null +++ b/setup.php @@ -0,0 +1,34 @@ +exec($sqlUsers); + echo "Table 'users' created successfully or already exists.
"; + + $sqlPets = "CREATE TABLE IF NOT EXISTS pets ( + id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, + user_id INT(6) UNSIGNED NOT NULL, + name VARCHAR(50) NOT NULL, + age INT(3) NOT NULL, + breed VARCHAR(50) NOT NULL, + photo_url VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE + )"; + $conn->exec($sqlPets); + echo "Table 'pets' created successfully or already exists.
"; + +} catch(PDOException $e) { + echo "Error: " . $e->getMessage(); +} + +$conn = null; +?> \ No newline at end of file