Link to home
Start Free TrialLog in
Avatar of shuboarder
shuboarderFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Help setting up mysql profiles with photos


I am new to php and mysql and am looking for a free script that can achieve the following:

1. Form that enables profile creation: e.g. name, dob, details password, etc. and photo to be submitted to a mysql database.

2. A page which displays all the photos in the mysql database that when clicked will take you to the appropriate profile.

I'll be looking at editing existing profiles later, but any help on setting up the 2 points above will be greatly appreciated!

Avatar of Muhammad Wasif
Muhammad Wasif
Flag of Pakistan image

Avatar of shuboarder


Hi wasifq,

I should have mentioned I have actually been through a number of tutorials already, including the ones listed which do not cover my question directly. Basically a google search on "php mysql tutorials" was how I found them.

Thanks for the reply though :)
create a unique id for each profile either by mysql AUTO_INCREMENT or php time();

then send the unique id thru the POST or GET methods when you click on the profile.
on the profile page, use something like this:

$sql = "
  SELECT * FROM table
  WHERE id=". $_GET['id'] .";

Make sure to add security as this can easily be hacked the way i have showed you, although it's the most basic.
Hi Oscurochu,

thanks for the advice, but I don't quite understand what you're getting at...

Here is my code so far....



<form action="insert.php" method="post" enctype="multipart/form-data">
  <p class="style1">First Name:       
    <input type="text" name="first">
Last Name:
<input type="text" name="last">
<input type="text" name="phone" />
<input type="text" name="mobile">
<input type="text" name="fax">
<input type="text" name="email">
<input type="text" name="web">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="file" name="photo">
  <span class="style1">
  <input type="submit" name="Submit" value="Submit!">





@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO Main VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web','$photo')";





@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM Main";



echo "<b><center>Database Output</center></b><br><br>";

while ($i < $num) {


echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><br>Photo: $photo<br><hr><br>";



Data is being added to the database just fine, however, the photo part is not working.
How can I adjust my code to get the photo to upload to my host and then have a page display all the photos that when clicked take you to the respective profile.

Hope this makes things clearer...

Thanks for your help so far!
Avatar of Eddie Shipman
What is your FIELDTYPE for your photo field?

To be honest with you, it is very inefficient to store images in a datbase. You should rethink your plan and
store the binary images in a location on your server and store the location in the database. This would be
a whole lot less headache on both the posting and viewing sides of the equation.
Hi Eddie,

yes I realised this...

The field type is a MEDIUMBLOB.

Ideally I want the photo to upload to a folder (lets call it upload) with a filename equal to the id number that it is uploaded with.

Then I would like a page that displays all the photos so that when a photo is clicked it takes you to the relevant profile.
Then you have to save your uploaded photos first, then store the location in the
database after saving the file, unless you know the name of the file before saving.

Not that difficult to do. I've even seen some free scripts that do this on

Hi Eddie,

thanks. Can you post the link to a script that achieves this?
Nothing specific but you can find one by searching these:
While those may not be exactly what you're looking for, the code behind one or more of them is usable
in your situation.
Hi Eddie,

thanks for the link, but after searching through the available scripts I really cannot find anything that is similar to my situation - which I find unbelievable!
I will find one for you.
All the scripts I saw, stored the filename in the database and the image in a directory.

But, you could base64 encode the photos and store them as longtext in the database.

Then, when you show them, decode them back before presenting them.

Not difficult and easier to manage than BLOBs.
Another option I found on forums said this:

You don't need to base64 encode and decode to store the image, you can load it into your script, then use mysql_escape_string on it, then do a direct insert. And no, you don't use stripslashes when you read it back out.

Or you can load the file directly into the db like:
UPDATE files SET data=LOAD_FILE($pathToFile) WHERE fileid=55
Hi Eddie,

No, i shouldn't really be storing the photos in the database, but I couldn't find an example that would allow me to upload the photos to a specific directory as the profiles are created.

Ideally, the uploaded photo should automatically rename itself to be the same as the record id.

i.e. When person 24 creates a new profile the photo (whatever it is called) will be renamed 24.jpg

I should then have a page that displays all the .jpgs and when any particular photo is clicked it takes you to the profile details.

Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A gallery of uploaded photos is not that hard, either. There are lots of gallery scripts out there.
Forced accept.

EE Admin