How to assign default image to user?

binay00713

Broken In
I am doing a website using Asp.net(c#)
My requirement is .
when the user registers,a default image should be assigned to him in the database which can be changed later.
suppose this default image is stored within a folder named image and the table name is user_reg & the column name is user_image
How to write code to assign the default image.
 

krishnandu.sarkar

Simply a DIGITian
Staff member
Ok, so when you are registering the user, and inserting the data in database, check if user selected any image, if not then insert user_image into user_reg along with other data.

If you are looking for the concept how to store image in database, store the path of the image.

So if no custom image selected by the user at the time of registration, implicitly insert the default image path in to database.

May be something like

if(imagecontrol.path == "")
{
path = default image path
}
else
{
path = imagecontrol.path
}

Now insert append the path variable while inserting. So it'll insert whatever it contains.
 

nishantve1

Broken In
Alright if you are using PHP heres what you can do
First make a comnection to the database and if the user has uploaded the image then the user_image column should have some address to the image like "images/userImages/myImage.jpg"
and if its empty we are gonna show the default pic so th ecode could go something like this

if you are into programming you know what 'id' is

$sql = mysql_query("SELECT * FROM users WHERE id='$lid'");

while ($row = mysql_fetch_assoc($sql)){

$location = $row['user_image'];
}

so this will give image location
and if its empty thats

if($location == "")
{
$location = "images/userImages/default/defaultpic.jpg";//address for your default pic
}

and then echo the $location out where the pic is to be displayed
and if the user wants to change it $location will just get updated and if the user will remove the pic it will get null and the user will see the default pic
 
Top Bottom