Sublime directory Surf the web anonymous Pagerank Monitor


displaying profile image thumbnail in the <example.php> page

emtor
Mon 30 April 2007, 12:17 pm GMT +0200
I'm a php/mysql newbie, and I have been playing around with access_user_class for about two weeks.
Today I wanted to find a way of displaying a profile thumbnail image when the user has logged in and goes to <example.php>.
To achieve this I created a folder in the filesystem to hold the imagefile, and a new field in the table <users> in the database to hold the URL to the imagefile.
Here's the php-code that was added to <example.php>, and I would like some comments to find out if I did this the correct way or not :

<img src="
<?php

#connecting to database
mysql_connect("localhost", "db_username", "db_password");
mysql_select_db("db_name");

#defines the variable $image

                # table name="users", field name that holds the URL to the imagefile="profile_thumb"

$image = mysql_query("SELECT profile_thumb FROM users WHERE login='$page_protect->user'")

or die(mysql_error());

#displaying the result of the db query
while($result_image = mysql_fetch_array( $image ))
{
echo $result_image['profile_thumb'];
}

#disconnecting from mysql
mysql_close();

?>
" border="1">

This is how the script works (. . . or at least how I think it works) :
The script accesses the database, finds the correct table, looks for the field that contains the image-URL's and finds the URL that belongs to the user that is currently logged in.
To find the correct username and the URL that belongs to it,  it uses the variable $page_protect->user
Instead of displaying the URL as text, it diplays the URL inside a <img src>-tag.

I would like some comments on this please. -Is this sensible php-scripting, or am I totally mistaken?
The script actually works, so maybe I'm at least on the right track  :)

olaf
Mon 30 April 2007, 12:30 pm GMT +0200
you should use one of the profile user fields, this way you can use the existing methods and you have no problems with later class updates

emtor
Mon 30 April 2007, 12:54 pm GMT +0200
I have been thinking the same,-using one of the fields in the profile user table would be better. The problem is, I would need more fields in the profile user table as time goes by. I've tried to use one of the existing fields, and even adding new fields but I can't make that work. Adding new fields to the profile user table is easy, but it seems like new fields need to be defined in some way so that the access_user_class can use them.
Being a newbie, this is something I don't understand.

olaf
Mon 30 April 2007, 12:56 pm GMT +0200
check this thread:

http://www.webdigity.com/index.php/topic,2345.0.adding+new+fields+to+the+profile+table.html

keep the user table clean otherwise you start suddenly your own branch :)

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional