Skip to content

Commit

Permalink
fix(register) fix check request
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmrval committed Jun 17, 2024
1 parent ca48276 commit 8d942f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
2 changes: 0 additions & 2 deletions components/homepage/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ function getFavorites($lineId) {
$query->execute([$_SESSION['user_id']]);
$lineIds = $query->fetchAll(PDO::FETCH_COLUMN);

echo $_SERVER['REMOTE_ADDR'];

?>

<div class="px-4 my-5 text-center">
Expand Down
37 changes: 21 additions & 16 deletions components/register/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,30 @@
}

if (!isset($errorMessage)) {
$query = $conn->prepare("INSERT INTO users (firstName, lastName, email, password) VALUES (:firstName, :lastName, :email, :password)");
$query->bindParam(':firstName', $_POST['firstName']);
$query->bindParam(':lastName', $_POST['lastName']);
$query->bindParam(':email', $_POST['email']);
$query->bindParam(':password', password_hash($_POST['password'], PASSWORD_DEFAULT));
$query->execute();

$query = $conn->prepare("SELECT COUNT(*) as count FROM users");
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);

if ($result['count'] == 1) {
$query = $conn->prepare("UPDATE users SET is_admin = 1 WHERE email = :email");
try {
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$query = $conn->prepare("INSERT INTO users (firstName, lastName, email, password) VALUES (:firstName, :lastName, :email, :password)");
$query->bindParam(':firstName', $_POST['firstName']);
$query->bindParam(':lastName', $_POST['lastName']);
$query->bindParam(':email', $_POST['email']);
$query->bindParam(':password', $password);
$query->execute();
}

header("Location: login.php");
exit();
$query = $conn->prepare("SELECT COUNT(*) as count FROM users");
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);

if ($result['count'] == 1) {
$query = $conn->prepare("UPDATE users SET is_admin = 1 WHERE email = :email");
$query->bindParam(':email', $_POST['email']);
$query->execute();
}

header("Location: login.php");
exit();
} catch (PDOException $e) {
$errorMessage = "Please fill correct values";
}
}
}

Expand Down

0 comments on commit 8d942f4

Please sign in to comment.