I am just stuck with this............Please Please Help

I got following fields in the forms for now
my form is as follow:

{ register.html }
<form action="register.php" method="post" enctype="multipart/form-data">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
Photo 1: <input type="file" name="photo"><br>
Photo 2: <input type="file" name="photo2"><br>
Photo 3: <input type="file" name="photo3"><br>
Photo 4: <input type="file" name="photo4"><br>
<input type="submit" name="register" id="button" value="Register">
Actually, Now I can upload four pictures into the images/user folder but with no thumbnails
Original Image : Remain same --> Upload
Thumbnail Image: Resize to 80 X 80 px --> Upload

Currently, it will upload four images with different unique random number for 4 images without dothing anything and put it into the database (image names only).

I want to create the thumbnail with the same name as the images name it will be in the database but with starting like:

Main image: myfile.jpg
Thumbnail: thmyfile.jpg

My register member with photo uploads. Page {register.php}

// allows you to use cookies
//gets the config page

if ($_POST[register]) {
$username = $_POST[username];
$password = $_POST[pass];

$ran1 = rand () ;

$ran1 = $ran1."_";

$ran2 = rand () ;
$ran2 = $ran2."_";

$ran3 = rand () ;
$ran3 = $ran3."_";

$ran4 = rand () ;
$ran4 = $ran4."_";

$folder = "images/users/";

$target = $folder .$ran1. basename( $_FILES['photo']['name']);
$target2 = $folder .$ran2. basename( $_FILES['photo2']['name']);
$target3 = $folder .$ran3. basename( $_FILES['photo3']['name']);
$target4 = $folder .$ran4. basename( $_FILES['photo4']['name']);

//thumb create
$target5 = $folder_th .$ran1. basename( $_FILES['photo']['name']);
$target6 = $folder_th .$ran2. basename( $_FILES['photo2']['name']);
$target7 = $folder_th .$ran3. basename( $_FILES['photo3']['name']);
$target8 = $folder_th .$ran4. basename( $_FILES['photo4']['name']);

//make variable for easier use
$pic = $ran1. basename( $_FILES['photo']['name']);
$pic2 = $ran2. basename( $_FILES['photo2']['name']);
$pic3 = $ran3. basename( $_FILES['photo3']['name']);
$pic4 = $ran4. basename( $_FILES['photo4']['name']);

if($username==NULL|$password==NULL) {
echo "A field was left blank.";
if($password != $cpassword) {
echo "Passwords do not match";

$password = md5($password);
$checkname = mysql_query("SELECT username FROM users WHERE username='$username'");
$checkname= mysql_num_rows($checkname);

$checkemail = mysql_num_rows($checkemail);
if ($checkname>0) {
echo "The usernameis already in use";
$username = htmlspecialchars($username);
$password = htmlspecialchars($password);

$pic = htmlspecialchars($pic);
$pic2 = htmlspecialchars($pic2);
$pic3 = htmlspecialchars($pic3);
$pic4 = htmlspecialchars($pic4);

$query ="INSERT INTO users (username, password pic, pic2 ,pic3, pic4)
VALUES('$username','$password','$pic','$pic2','$pic3','$pic4' )";

$res=mysql_query($query) or die ("Error: ". mysql_error(). " with query ". $query);

echo "You have successfully registered!";
echo "<br />";

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
echo "Image 1 has been added";
echo "<br />";

else {

echo "Sorry, there was a problem uploading Image 1.";

if(move_uploaded_file($_FILES['photo2']['tmp_name'], $target2))
echo "Image 2 has been added";
echo "<br />";

else {

echo "You didn't upload Image 2.";
echo "<br />";

if(move_uploaded_file($_FILES['photo3']['tmp_name'], $target3))
echo "Image 3 has been added";
echo "<br />";

else {
echo "You didn't upload Image 3.";
echo "<br />";

if(move_uploaded_file($_FILES['photo4']['tmp_name'], $target4))

echo "Image 4 has been added";
echo "<br />";

else {
echo "You didn't upload Image 4.";
echo "<br />";

include 'register.html'; }

Please help me how can I do with this script,By the way if anybody knows any free script to upload 4 photos with thumbnail
and insert into the dabase, name only.

Thanks a lot for your help