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 :)
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 :)