Jump to content

[SOLVED] else statement


squiblo

Recommended Posts

ok my aim here is to view the profile image if they have uploaded one, but if they have not uploaded one i want to view another image, i have started already but got stuck trying to view another image if they havent uploaded one...

 

<?php

session_start();

include("checklogin.php");

$username = $_SESSION['myusername'];

$query = mysql_query("SELECT * FROM members WHERE username='$username'");
if (mysql_num_rows($query)==0)
   die("User not found!");
else
{

$row = mysql_fetch_assoc($query);
$location = $row['imagelocation'];
echo "<img src ='$location' width='225' height='275'>";
}


?>

 

the path to the image if they havent uploaded one is...

/profileimages/box.png

Link to comment
Share on other sites

If I understand what you want to do correctly.  After your if remove the die and echo the other image.

**Edit**

I did not understand correctly.

In your else you could do

if($location!='')
echo "<img src ='$location' width='225' height='275'>";
else
echo "<img src='/profileimages/box.png'>";

Link to comment
Share on other sites

Something like this should do the trick.

 

<?php

session_start();

include("checklogin.php");

$username = $_SESSION['myusername'];

$query = mysql_query("SELECT * FROM members WHERE username='$username'");
if (mysql_num_rows($query)==0){
die("User not found!");
}else{
$row = mysql_fetch_assoc($query);
$location = $row['imagelocation'];
if($location == ""){
	echo "<img src ='/profileimages/box.png' width='225' height='275'>";
}else{
	echo "<img src ='$location' width='225' height='275'>";
}
}


?>

Link to comment
Share on other sites

that worked perfect thankyou, i have linked the images, but it puts a purple border on, how can i stop this?

 

<div id="wb_Shape5" style="position:absolute;left:84px;top:240px;width:225px;height:275px;z-index:11" align="center"><a href="/upload.php">
<?php

session_start();

include("checklogin.php");

$username = $_SESSION['myusername'];

$query = mysql_query("SELECT * FROM members WHERE username='$username'");
if (mysql_num_rows($query)==0){
   die("User not found!");
}else{
   $row = mysql_fetch_assoc($query);
   $location = $row['imagelocation'];
   if($location == ""){
      echo "<img src ='/profileimages/box.png' width='225' height='275'></a>";
   }else{
      echo "<img src ='$location' width='225' height='275'>";
   }
}


?>
</a></div>

Link to comment
Share on other sites

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.