last day (14 days later) » 

6:12 AM
2
A: Page keeps on loading. PHP

HenriSolved. My mistake was: public function profile_photo($name_id){ $sql = "SELECT * FROM users WHERE img_id= :img_id"; $q = $this->db->prepare($sql); $q->execute(array(':img_id'=>$name_id)); $result = $q->fetchALL(PDO::FETCH_ASSOC); if($result[0]['img_id'] =...

 
Winner, good job haha.
 
@Darren but still I don't get why it should work. Because $name_id = $_SESSION['user']['uid'] .. Any explanation?
 
Because you aren't setting $name_id anywhere in that function. (as far as I can see)
 
@Darren That's correct lol. thanks anyways
@Darren can i as you something?
 
Sure, go for it mate.
 
6:12 AM
public function profile_photo($name_id){ $sql = "SELECT * FROM users WHERE img_id= :img_id"; $q = $this->db->prepare($sql); $q->execute(array(':img_id'=>$name_id)); $result = $q->fetchALL(PDO::FETCH_ASSOC); foreach($result as $row){ if($row['img_id'] == $_SESSION['uid']){ echo "<img id='profile_img' src='test/upload/".$name_id."_".$row['image']."'/>"; }else if($row['img_id'] != $_SESSION['uid']){ echo "<img id='profile_img' src='classversiondontdelete/images/default/profile_icon.gif'/>"; } } return $result; }`
 
Whats the question?
 
If a user has a pic uploaded, the pic displays fine. If not the default pic doesn't display. Im using the following code. Updated it.
Hello Daren
 
hey mate, so whats the question?
 
If a user has a pic uploaded, the pic displays fine. If not the default pic doesn't display. Im using the following code. Updated it.
public function profile_photo($name_id){ $sql = "SELECT * FROM users WHERE img_id= :img_id"; $q = $this->db->prepare($sql); $q->execute(array(':img_id'=>$name_id)); $result = $q->fetchALL(PDO::FETCH_ASSOC); foreach($result as $row){ if($row['img_id'] == $_SESSION['uid']){ echo "<img id='profile_img' src='test/upload/".$name_id."_".$row['image']."'/>"; }else if($row['img_id'] != $_SESSION['uid']){	echo "<img id='profile_img' src='classversiondontdelete/images/default/profile_icon.gif'/>"; } } return $result; }`
this is my code
 
6:29 AM
So what exactly is wrong?
 
the else is not displaying
if the user doesnt have an profile pic uploaded, the default pic which is the line else if($row['img_id'] != $_SESSION['uid']){ echo "<img id='profile_img' src='classversiondontdelete/images/default/profile_icon.gif'/>"; } should display
 
Take out that whole else if(...) bit and just have a normal else
 
still the same problem
 
So this: `if ($row['img_id'] == $_SESSION['uid']) {
echo "<img id='profile_img' src='test/upload/" . $name_id . "_" . $row['image'] . "'/>";
} else {
echo "<img id='profile_img' src='classversiondontdelete/images/default/profile_icon.gif'/>";
}` doesnt work?
 
that is correct. No luck :(
 
6:40 AM
So you DONT want that image to show?
 
i want the image to show.
i want the else to execute if the user didnt upload a pic give a default pic
 
What is it stored in the database as?
 
i dont get in the db
straight from the folder on my site
 
Why don't you check if the file exists? i.e.
if ($row['img_id'] == $_SESSION['uid'] && file_exists(ROOT_DIR . "test/upload/" . $name_id . "_" . $row['image'] )) {
echo "<img id='profile_img' src='test/upload/" . $name_id . "_" . $row['image'] . "'/>";
} else {
echo "<img id='profile_img' src='classversiondontdelete/images/default/profile_icon.gif'/>";
}
 
i know if doest exist because its a default pic that i have to display if user currently didnt upload their pic.
 

last day (14 days later) »