Member Avatar for JayGeePee

I was wondering if someone could tell me how I can set a default image to auto increment, when one of my members sign up. I cant figure out how to set this in phpmyadmin. I could do it manually, but I'd rather it be automatically.

I dont quite know what you mean with "auto-increment", do you mean the filename (e.g. the first user has unknown1.jpg and the second unknown2.jpg????)? Anyway, you can set a default value for a column by using DEFAULT in sql:

ALTER TABLE users ADD image DEFAULT 'unknown.jpg'

or,

ALTER TABLE users ALTER image SET DEFAULT 'unknown.jpg'
Member Avatar for JayGeePee

Thanks, Works perfectly. I didnt realize it was that easy. I actually used the default box in sql, but I didnt test it right. It only works on new members, and not the members who were signed up already. I signed up as a test member and it worked. I actually didn't mean auto increment, I just meant automatically.

The image displays in my members area so the member can see it, but I still cant figure out how I can get it to show on my members website, when there URL is opened in the browser.

How do I add an extra box in my image upload form for stuff like there name, and phone number? Text Boxes that will submit along with there image.

Member Avatar for diafol

FIRST
If you've used method 2, I assume you want to add the default image to existing members who don't have an image:

UPDATE users SET image = 'default.jpg' WHERE image = ''

SECOND
You need to supply more info on what you mean.

THIRD

<label for="username">Name:</label>
<input name="username" id="username" type="text" />
Member Avatar for JayGeePee

I've got everything working as far as my members uploading there images goes. But I still cant figure out how to get there image to display outside the members area when there unique url is in the browser.

examples:
www.mysite.com - is my site...
www.mysite.com/userid - is there site. <------ I want there image to display here.

I keep saying like myspace, when you upload a photo from inside your control panel, it displays on your url - www.myspace.com/yourname.

I cant figure this out... There image works perfectly inside the members area. When they upload it, it goes to a folder on my server, and in a table in phpmyadmin.

I echoed a $row to display the image inside the members area.

Any pointers would be helpful...

i think this has something with .htaccess to do...

You must rewrite:

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^picture/([a-zA-Z0-9.,!_-]+)$ avatar.php?id=$1


first get avatar.php?id=1 or avatar.php?id=filename.jpg whatever you use to display it!

Member Avatar for JayGeePee

So in order to get this to work, what do I do? The location of my images on my server is under "pictures/". The name of the table in my database is 'members' and the field name for the picture is 'imagelocation'.

There url looks exactly like below -
http://www.mysite.com/index.php?referid=somename

What do I do to this -
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^picture/([a-zA-Z0-9.,!_-]+)$ avatar.php?id=$1

and where do I use this -
avatar.php?id=1 or avatar.php?id=filename.jpg

How do I get the above examples to work with my setup?

Member Avatar for diafol

I'm not really following this very well at all. Are you getting problems viewing the images in a particular page?

smartness is talking about .htaccess files NOT php. As far as I can tell, this should sort your problem w.r.t getting member info on a member page, where the URL is rewritten automatically. That is, when a user enters example.com/somename this is actually passed to the server as example.com?id=somename.

Google .htaccess to find out more, it's not v. difficult. One tip - call the file htaccess.txt before you FTP it, then rename it to .htaccess in situ.

Now if I'm getting you, you want the page name to display the member details (including avatar).

This should be straightforward.

If you have a querystring with either the member name (unique) or the member id, everything regarding the member should be available via $_GET and good old SQL.

Say you're on example.com?user=maverick OR even if address bar displays example.com/maverick (assuming you're using .htaccess):

//set $imgdirectory and db connections previously

if(isset($_GET['user']) && $_GET['user'] <> ""){
   //escape quotes and html tags
   $user = addslashes(htmlentities($_GET['user']));
   $result = mysql_query("SELECT * FROM users WHERE username = '{$user}'");
   if(mysql_num_rows($result) > 0){
      $data = mysql_fetch_array($result);
      //the following assume that you disallow HTML, otherwise use html_entity_decode()
      $name = stripslashes($data['username']);
      $loc = stripslashes($data['location']);
      $hobbies = stripslashes($data['hobbies']);
      $faves = stripslashes($data['faves']);
      $avatar = $imgdirectory . "/" . stripslashes($data['avatar']);    
      
      //you should now have all your member variables to hand and locate/format as you wish, e.g. <img src="{$avatar}" />

   }else{
      //return no user with that name
   }
}

I'm sorry if that isn't what you need, I get confused - it's my age.

Member Avatar for JayGeePee

No its not what i'm looking for... All I want to do is display my members image, name, and phone number outside of the members area, when there url - is in the browser.

www.mysite.com/somename

<image>
<name>
<phone>

pretty much like myspace or facebook... You go to www.myspace.com/somename and you see the information that the member saved in the members area.

Why should the image increament?

Member Avatar for JayGeePee

Why should the image increament?

I figured this out, i meant automatically.

I'm just looking to display member content outside of the members area.

Member Avatar for diafol

Doh! I think I see what you're getting at. You want to give the avatar a specific filename so that it doesn't overwrite any other image files.

If you give it a name on file upload of say "avatar" + user id and the original extension (png, jpg or gif).

e.g. "avatar125.jpg" will be stored in the avatars folder for user number 125. In addition the avatar field in the db should only contain the extension, in this case 'jpg'. This way you can build the avatar image from knowing the user id ->

When you query the db for the user (from username data in $_GET array):

e.g. SELECT * FROM user WHERE username = '{$username}' where $username is the cleaned $_GET variable.

get the user id and place it in $user_id variable.
get the avatar file extension and place it in $ext variable.

<img src="avatar{$user_id}.{$ext}" />

There is now no need to autoincrement the image name - just apply the user id to whom it belongs.

I hope I got it right this time, or I'm gonna feel really twp.

Member Avatar for JayGeePee

How can I display images from a different folder/directory on a chosen URL?

Member Avatar for JayGeePee

Is there a way to detect the url in the browser and than you use this to display certain images and data from my database?

Member Avatar for JayGeePee

That's what I've saying! Use .htaccess to 'transform' example.com/somename to example.com?username=somename

Please Google htaccess rewrite if you don't understand. Over and out.

I googled it but couldnt fing anything to do this. Or mabey i just dont know what im looking for.

Member Avatar for diafol

create htaccess.txt in Notepad then paste this into it:

Options +FollowSymLinks
RewriteEngine on

RewriteRule /member/(.*)/ www.example.com?member=$1

Upload this file to public root directory via FTP

Rename the file in situ to .htaccess (note the period in front of the filename, well technically is doesn't have a filename now, just an extension).

If you enter www. example.com/member/orangeman into the address bar of your browser, the server will receive it as www. example.com?member=orangeman

The page will still recognize the $_GET variable, so you can use this to query the db and output that member's (orangeman in this case) details.

Member Avatar for diafol

OK how's this?

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?referid=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?referid=$1

This will change www. example.com/index.php?referid=orangeman

to

www. example.com/orangeman

In the example I've given the username is used as opposed to the integer user_id. htaccess won't do a db search - so you'll need to use the username for searching the db.

Member Avatar for JayGeePee

This may be a stupid question, but I was wondering if you could use a cookie variable to display content from my database. This is how my site is setup. When someone clicks on the referral links I've been mentioning, it sets a cookie for the user that brings them back to that same referral everytime they visit the site. So if they click www.mysite.com/somename, unless they delete there cookie history or dont have it on at all - they go to the same link every time.

Is there a way to use the cookie variable thats set for that "somename" to display content from the database for somename?

I dont know if im making any sense at all...

Member Avatar for diafol

I don't see the point. htaccess will enable you to enter the url you want and the $_GET variable in the index.php page will then give you a hook to the db to extract the user's details. That's it. Cookies shouldn't really feature here. The htaccess method will work whether cookies are enabled, eaten, disabled etc etc.

There are 20 ways to boil an egg, but I think using cookies for this will leave it raw.

Have you tried my suggestion?

commented: eaten....nice. +6
Member Avatar for JayGeePee

I don't see the point. htaccess will enable you to enter the url you want and the $_GET variable in the index.php page will then give you a hook to the db to extract the user's details. That's it. Cookies shouldn't really feature here. The htaccess method will work whether cookies are enabled, eaten, disabled etc etc.

There are 20 ways to boil an egg, but I think using cookies for this will leave it raw.

Have you tried my suggestion?

I have tried it, but it dont seem to do anything... None of my member urls exist on my server... They all reside on my database.

www.Mysite.com/username

I bought this php script from a guy who closed down his website shortly after... So I had no way of contacting him with questions.

If mysite.com/somename dosnt exist on my server as a visible URL. Does this .htaccess file still work on a url thats not visible? I think this url is set in my script I bought, and the only evidence i have that its there is my admin panel, or my database.

I dont know if im going to get this to work...

Member Avatar for diafol

I have tried it, but it dont seem to do anything... None of my member urls exist on my server... They all reside on my database.

Obviously.

Use this with the htaccess file in place:

index.php - I wouldn't use this on the index.php, I'd change it to member.php or something, but it's your funeral.

if(isset($_GET['username'])){
  $username = addslashes(htmlentities($_GET['username']));
  $recordset = mysql_query("SELECT * FROM users WHERE username = '{$username}'");
  if(mysql_num_rows($recordset) > 0){
     $data = mysql_fetch_array($recordset);
     $avatar = $data['avatar'];

     (... etc for all the fields you want ...)

  }else{
     //put message to screen if user doesn't exist
  }
}
commented: Great Persistence...Master Coder! +1
Member Avatar for JayGeePee

Solved... Thanks for your persistence, most people would of gave up on me. I didnt upload my .htaccess file right, the first way you told me to do it worked. Persistance pays off. Thanks.

Member Avatar for diafol

Da nada, Jay - glad you made it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.