Jump to content

Setting profile picture


rvdveen27

Recommended Posts

Hello all, 

 

I'm trying to configure the profile picture code so users can set their own profile picture only I'm experiencing some issues. 

 

Currently I have it set like this (which does not show the picture, but it does recognize the entry in the database is not NULL): 

						<div class="well well-sm" style="width: 500px;">
							<a href="#" class="thumbnail">
								<?php if($row['avatar'] = NULL): ?>
								<img data-src="holder.js/200x200" alt="...">
								<?php else: ?>
								<img src="<?php echo $row['avatar']; ?>">
								<?php endif; ?>
							</a>
							<?php echo $row['avatar']; ?>
						</div>

Now I don't believe this is the most efficient way to do this but more of an alternative(?). I did this because otherwise the 200x200 image it's showing does not get overwritten/overruled by the image link in the database. So if anyone has a more efficient way of doing this then feel free to share.

 

Before it looked like this: 

						<div class="well well-sm" style="width: 500px;">
							<a href="#" class="thumbnail">
							  <img data-src="holder.js/200x200" alt="...">
							</a>
						</div>

My query looks like this: 

	$userid = $_GET['id'];
	$userid = intval($userid);

	if(!is_numeric($userid))
	{
		header("Location: index.php");
		exit;
	}
	
	$submitted_username = ''; 
		
        $query = " 
            SELECT 
                username 
                ,email
				,verified
				,suspended
				,regdate
				,admin
				,avatar
				FROM users 
            WHERE 
                id = :id 
        "; 
        $query_params = array( 
            ':id' => $userid

Hoping anyone can help me with this issue. Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/296955-setting-profile-picture/
Share on other sites

You need to be using the comparison operator == (two equals) not the assignment operator = (one equals) when comparing values here. Or use empty

<?php if($row['avatar']) = NULL: ?>

 

Now I don't believe this is the most efficient way to do this but more of an alternative(?)

And alternative way of writing that if/else would be

<?php $avatarImage = empty($row['avatar']) ? 'holder.js/200x200' : $row['avatar']; /* use ternary operator to define what image to server for avatar*/ ?>
<img data-src="<?php echo $avatarImage; ?>" alt="...">

See my edit in the main post. I accidentally put " = NULL" outside of the brackets (), which caused the page to break. Now having that inside the brackets made it work, however it's not showing a image. 

 

It seems it's completely ignoring

<?php echo $row['avatar']; ?>

 within and after the 

<?php if($row['avatar'] = NULL): ?>
...
<?php else: ?>
...
<?php endif; ?>

Placing it before this, makes it work just fine.

How is $row defined?

 

Its because you are using = NULL not == NULL

 

= NULL will be overriding the value for $row['avatar']

 

As I said earler

 

You need to be using the comparison operator == (two equals) not the assignment operator = (one equals) when comparing values here. Or use empty

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.