-
Welcome!
-
Your project is ready to conquer the peaks.
-
PHP version: = htmlspecialchars($phpVersion) ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
\ 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.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
+
+
+
+
+
+
+
\ 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
+
+
+
+
+
+
+
+
![<?= htmlspecialchars($pet['name']) ?>](<?= htmlspecialchars($pet['photo_url']) ?>)
+
+
= htmlspecialchars($pet['name']) ?>
+
+ Breed: = htmlspecialchars($pet['breed']) ?>
+ Age: = htmlspecialchars($pet['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
+
+
+
+
+
+
+
\ 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