Jump to content

Recommended Posts

Hi Guys,

 

i have a script here that echoes out a users photo (if they have uploaded one) if not it's just a generic one, what i was wanting to do is display a generic male one if they are male and a female pic if they are female, the code just now is:

 

<?php     
     // Start retrieving user profile from database//////////////////////////////////////
    $qProfile = "SELECT * FROM membership WHERE username='$member'";
    $rsProfile = mysql_query($qProfile) or die(mysql_error());

    $row = mysql_fetch_array($rsProfile); // get the resultset into an array/////////////
    extract($row);
    
    // The row items in variables.../////////////////////////////////////////////////////
    $id = $row['id'];
    $photo1 = $row['photo1'];
    $gender = $row['gender'];
?>
<p>Upload Main Profile Photo<p>
<table width="600" cellspacing="2" cellpadding="2">
<form action="upload_photo_done.php" method="POST" enctype="multipart/form-data">
<tr>
<td bgcolor="#E2E2E2">Upload Location:</td><td bgcolor="#E2E2E2" align="left"><input type="file" name="image1" size="40"></></td>
<tr>
<td bgcolor="#E2E2E2">Current Uploaded Photo:</td><td bgcolor="#E2E2E2">
    <?php     
    if($photo1 == 0) {         
     echo "<img src='uploads/no_pic_male.jpg' />";           
       } else {            
     echo "<img src='uploads/$photo1' border='0' />"; 
}
?>

 

i was thinking an elseif statement is that possible?

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/50618-displaying-gender-photo/
Share on other sites

If they didn't upload a photo the the value stored in the database field 'photo1' really is 0 or is it empty?

 

if it's empty:

<?php     
    if(empty($photo1)) {         
      switch ($gender) {
              case "male": echo "<img src='uploads/no_pic_male.jpg' />"; break;
              case "female": echo "<img src='uploads/no_pic_female.jpg' />"; break; 
              default: echo "<img src='uploads/no_pic.jpg' />"; break; 
       } else {            
     echo "<img src='uploads/$photo1' border='0' />"; 
}
?>

 

If it's 0 just leave the if statement as you already had it.

Hi Guys,

 

Thanks for the help the $photo1 field was indeed empty.

 

i have implemented this code by Nikki

 

<?php     
    if(empty($photo1)) { 
            
      switch ($gender) {
      
              case "Male": echo "<img src='images/no_pic_male.jpg' />"; 
              break;
              
              case "Female": echo "<img src='images/no_pic_female.jpg' />";
              break;     
       }
              
       } else {  
                 
              echo "<img src='uploads/$photo1' border='0' />"; 
}
?>   

 

this does the job it echoes out a female or a male picture depending on signup, only thing is, when i upload a photo in the control panel, it doesn't store the name in mysql (even though it says uploaded succesfully) but if i revert to my initial basic code:

 

    <?php     
    if($photo1 == 0) {         
     echo "<img src='uploads/no_pic_male.jpg' />";           
       } else {            
     echo "<img src='uploads/$photo1' border='0' />"; 
}
?>

 

it seems to work as before, storing the name in mysql any ideas on why it didn't do this with the revised code?

 

thanks guys

 

Graham

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.