Jump to content

Setting profile picture


Go to solution Solved by Ch0cu3r,

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.

Edited by rvdveen27
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="...">
Edited by Ch0cu3r

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.

Edited by rvdveen27
  • Solution

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

Edited by Ch0cu3r
  • Like 1
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.