Profile and user.php don't immediately crash

This commit is contained in:
Floorb 2021-07-12 10:46:52 -04:00
parent c8614b24cd
commit 970cda9f2e
3 changed files with 6 additions and 9 deletions

View file

@ -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 {

View file

@ -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');

View file

@ -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();