0

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.

5
Contributors
24
Replies
25
Views
7 Years
Discussion Span
Last Post by diafol
Featured Replies
  • 1
    diafol 3,669   7 Years Ago

    I don't see the point. htaccess will enable you to enter the url you want and the $_GET['username'] 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 … Read More

  • 1
    diafol 3,669   7 Years Ago

    [QUOTE]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. [/QUOTE] Obviously. Use this with the htaccess file in place: [B]index.php[/B] - I wouldn't use this on the index.php, I'd change it to member.php … Read More

0

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'
0

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.

0

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" />
0

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

0

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!

0

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?

0

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.

0

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.

0

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.

0

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.

0

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

0

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?

0

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.

Edited by diafol: n/a

0

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.

0

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

1

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?

Edited by diafol: n/a

Votes + Comments
eaten....nice.
0

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

1

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
  }
}

Edited by diafol: n/a

Votes + Comments
Great Persistence...Master Coder!
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.