rvdveen27 Posted June 22, 2015 Share Posted June 22, 2015 (edited) 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 June 22, 2015 by rvdveen27 Quote Link to comment https://forums.phpfreaks.com/topic/296955-setting-profile-picture/ Share on other sites More sharing options...
Ch0cu3r Posted June 22, 2015 Share Posted June 22, 2015 (edited) 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 June 22, 2015 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/296955-setting-profile-picture/#findComment-1514588 Share on other sites More sharing options...
rvdveen27 Posted June 22, 2015 Author Share Posted June 22, 2015 (edited) 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 June 22, 2015 by rvdveen27 Quote Link to comment https://forums.phpfreaks.com/topic/296955-setting-profile-picture/#findComment-1514589 Share on other sites More sharing options...
Solution Ch0cu3r Posted June 22, 2015 Solution Share Posted June 22, 2015 (edited) 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 June 22, 2015 by Ch0cu3r 1 Quote Link to comment https://forums.phpfreaks.com/topic/296955-setting-profile-picture/#findComment-1514592 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.