diff --git a/includes/functions.php b/includes/functions.php index 96c5348..dcde97a 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -263,14 +263,11 @@ function jsonView($paste_id, $p_title, $p_conntent, $p_code) { } -function getTotalPastes($conn, $username) { - $count = 0; - $query = $conn->prepare("SELECT member FROM pastes WHERE member=?"); +function getTotalPastes(PDO $conn, string $username) : int { + $query = $conn->prepare("SELECT COUNT(*) FROM pastes WHERE member = ?"); $query->execute([$username]); - while ($row = $site_info_rows->fetch()) { - $count = $count + 1; - } - return $count; + + return intval($query->fetch(PDO::FETCH_NUM)[0]); } function isValidUsername(string $str) : bool { diff --git a/profile.php b/profile.php index b168ed9..7cd4d12 100644 --- a/profile.php +++ b/profile.php @@ -74,7 +74,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { updatePageViews($conn); -$total_pastes = getTotalPastes($con, $user_username); +$total_pastes = getTotalPastes($conn, $user_username); // Theme require_once('theme/' . $default_theme . '/header.php'); diff --git a/user.php b/user.php index fbef95c..42695c9 100644 --- a/user.php +++ b/user.php @@ -28,7 +28,7 @@ $user_username = trim($_SESSION['username']); if (isset($_GET['user'])) { $profile_username = trim($_GET['user']); - if (!existingUser($con, $profile_username)) { + if (!existingUser($conn, $profile_username)) { // Invalid username header("Location: ../error.php"); die();