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
https://forums.phpfreaks.com/topic/168017-solved-else-statement/
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'>";

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'>";
}
}


?>

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.