I just started learning more about functions and am currently stuck on one part of them. I am trying to get the result of the function that I set in the return to populate in html in a specific spot.
Does anyone see what I am doing wrong?
Here is the error message:
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function profilePic(), 0 passed in /adminNav.php on line 76 and exactly 1 expected in /adminNav.php:6 Stack trace:
0 /adminNav.php(76): profilePic()
1 /admin/project-gallery.php(93): include('pub...')
2 {main} thrown in /adminNav.php on line 6
Full code:
function profilePic($con) {
try {
//Profile pic in main
$sqlProfileImg = "
SELECT *
FROM profile_img
WHERE user_id = ?
ORDER BY id DESC
LIMIT 1
";
if ($stmtProfileImg = $con->prepare($sqlProfileImg)) {
$stmtProfileImg->execute(array($user_id));
$default_profile_img = NULL;
$userProfilePic = NULL;
$profilePic = NULL;
$profilePicRows = $stmtProfileImg->fetchAll(PDO::FETCH_ASSOC);
foreach ($profilePicRows as $profilePicRow) {
$profilePic = $profilePicRow['img'];
$profilePic = (!empty($profilePic) && $profilePic != 0)? $profilePic : "profile_images/default.jpg"; ?>" alt="<?php echo (!empty($profilePic) && $profilePic != 0)? "Profile Picture" : "No Picture";
}
}
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
$date = new DateTime();
file_put_contents('error_log_profile_pic', "
[{$date->format('Y-m-d H:i:s')}]" . "Error adding attachment:
" . print_r($e, 1), FILE_APPEND);
return false;
}
return $profilePic;
}
HTML
<img id="navUserProfilePic" src="<?php profilePic(); ?>">