Jump to content

Profile Banner Image Problem


White_Lily

Recommended Posts

Sorry for all the problems im having im not entirly sure why of all them are occuring since the majority are things i have done in the past.

 

Anyway - to the point of this new problem, i have created a user profile where the user can have a profile banner and an avatar, however the banner shows the default image even if there is an image in the database.

 

here's the profile php code:

 


<?php
if(!$loggedUser && !$loggedPass){
echo '<div class="navigation">';
$nav = select("*", "pages", NULL, "pageType ASC");
$num = mysql_num_rows($nav);

if($num != 0){

echo "<ul>";
while($get = mysql_fetch_assoc($nav)){
$filename = file_exists($_SERVER['DOCUMENT_ROOT'].$get["pageFileName"]);
if($get["pageType"] <= 2 && $get["active"] == 1){
if($filename){
echo "<li><a href='".$GLOBALS["siteUrl"]."/".$get["pageFileName"]."'>".$get["pageName"]."</a></li>";
}
}
}
echo "</ul>";
}else{
echo "No menu found.";
}

echo '</div>';
echo '<div class="content">';
echo '<h1>Welcome</h1>';
echo '<h3>Login</h3>';

include "inc/loginCheck.php";

echo '<form action="" method="POST">';
echo '<label>Username:</label><input type="text" name="username" />';
echo '<label>Password:</label><input type="password" name="password" />';
echo '<input type="submit" name="submit" value="Login" />';
echo '</form>';
echo '</div>';
}else{
echo '<div class="navigation">';
$nav = select("*", "pages", NULL, "pageType ASC");
$num = mysql_num_rows($nav);

if($num != 0){

echo "<ul>";
while($get = mysql_fetch_assoc($nav)){
$filename = file_exists($_SERVER['DOCUMENT_ROOT'].$get["pageFileName"]);
if($get["pageType"] > 0 && $get["active"] == 1){
if($filename){
$convertLink = str_replace("Home", "Profile", $get["pageName"]);
echo "<li><a href='".$GLOBALS["siteUrl"]."/".$get["pageFileName"]."'>".$convertLink."</a></li>";
}
}else{
echo "<li>No active navigation.</li>";
}
}
echo "<li><a href='logout.php'>Logout</a></li>";
echo "</ul>";
}else{
echo "No menu found.";
}
echo '</div>';
echo "<div class='banner'>";
echo "<div class='bannerImage'>";
$banner = getbanner("lightbox");
echo $banner;
echo "</div>";
echo "</div>";
echo '<div class="content">';
echo "<div class='userDetails'>";
echo "<div class='avatarUser'>";

echo "</div>";
echo "<div class='accountDetails'>";
echo '<h1>'.$loggedUser."'s ".$page.'</h1>';
echo "</div>";
echo "</div>";
include "inc/profile.php";
echo '</div>';
}
?>

 

and here is the funtion that the banner calls once the user has logged in:

 

<?php

//Banner Image(s)
function getBanner($rel){
$query = select("*", "users", "username = '$loggedUser'");
$fetch = mysql_fetch_assoc($query);
$bannerImg = $fetch["bannerImage"];
$link = "<a href='".$GLOBALS["siteUrl"]."/images/banners/".$bannerImg."' rel='".$rel."'>";
$Img = "<img src='".$GLOBALS["siteUrl"]."/images/banners/".$bannerImg."' />";
$close = "</a>";
$default = "<img src='".$GLOBALS["defaultImage"]."' />";

$acutalImg = $link.$Img.$close;

if($actualImg){
return $actualImg;
}else{
return $default;
}

}
?>

Link to comment
Share on other sites

Ok, you make a call to the function getBanner() which is supposed to return either the user's banner or the default. And you're saying that the default is always returned right? So, here is that function:

function getBanner($rel)
{
$query = select("*", "users", "username = '$loggedUser'");
$fetch = mysql_fetch_assoc($query);
$bannerImg = $fetch["bannerImage"];
$link = "<a href='".$GLOBALS["siteUrl"]."/images/banners/".$bannerImg."' rel='".$rel."'>";
$Img = "<img src='".$GLOBALS["siteUrl"]."/images/banners/".$bannerImg."' />";
$close = "</a>";
$default = "<img src='".$GLOBALS["defaultImage"]."' />";

$acutalImg = $link.$Img.$close;

if($actualImg)
{
 return $actualImg;
}else{
 return $default;
}
}

 

I see a few problems with that function. Even if you fixed the problem it would still not work as you want. Let's go through it line by line:

 

$query = select("*", "users", "username = '$loggedUser'");

Looks like you have a custom function for running a SELECT query? Not sure why, but OK. 1) why are you selecting * when you only need the image? 2) $loggedUser has not been defined in the function so that value would always be empty. 3) Not sure why you are using the username instead of the userID which you should have in the table.

 

$fetch = mysql_fetch_assoc($query);

You should do a check to see if any record was even returned before you try and fetch the data.

 

$bannerImg = $fetch["bannerImage"];

Yeah, you need to check if any record was returned first.

 

 $link = "<a href='".$GLOBALS["siteUrl"]."/images/banners/".$bannerImg."' rel='".$rel."'>";
$Img = "<img src='".$GLOBALS["siteUrl"]."/images/banners/".$bannerImg."' />";
$close = "</a>";
$default = "<img src='".$GLOBALS["defaultImage"]."' />";

$GLOBALS ?!?!? Really? That's very poor form.

 

$acutalImg = $link.$Img.$close;

Interesting name for that variable, don't you think?

 

 if($actualImg)
{
 return $actualImg;
}else{
 return $default;
}

First of all, that condition is checking the wrong variable - you misspelled it when you set it previously. Second, that will ALWAYS return true since you just set the value before you did that check. You need to check if the returned value (if there was one) had a non-null value to determine whether to show the default or not. $actualImg will always have a value as you have coded it.

 

I have rewritten the function below. You need to now pass the values for $loggedUser and $rel. Ideally I would also pass the values you are referencing using $GLOBAL, but I was lazy

 

This should get you closer to what you want

//Banner Image(s)
function getBanner($loggedUser, $rel)
{
//Define return value as default
$banner = "<img src='{$GLOBALS['defaultImage']}' />";
//Run query
$query = select('bannerImage', 'users', "username='$loggedUser'");
//Determine if record was returned
if($query != false && mysql_num_rows($query)>0)
{
 $bannerImg = mysql_result($query, 0);
 //Determine if value was empty
 if(!empty($bannerImg))
 {
	 //Redefine return value
	 $imgURL = "{$GLOBALS['siteUrl']}/images/banners/{$bannerImg}";
	 $banner = "<a href='{$imgURL}' rel='{$rel}'><img src='{$imgURL}' /></a>";
 }
}

return $banner;
}

Edited by Psycho
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.