$query3 = mysql_query("SELECT * FROM `pictures` WHERE `picno` = '{$picnoarray[$x]}'");
    while ($row = mysql_fetch_array($query3)) {
        $name[$x] = $row['name'];
        $catArray[$x] = $row['category'];
        //Retrives category details
        $query4 = mysql_query("SELECT * FROM `category` WHERE `categoryno` = '{$catArray[$x]}'");
        while ($row1 = mysql_fetch_array($query4)) {
            $path[$x] = $row1['path'];
        }
        // while
    }
    // while
}
// for
// Calls printpic function
printpic($name, $path, $catArray, $picnoarray);
if ($decoy == 0) {
    // Calls insertdb function
    insertdb($name, $path, $picnoarray);
}
// Inserts decoy images.
function insertdb($name, $path, $picnoarray)
{
    $username = $_SESSION['username'];
    $type = $_SESSION['type'];
    for ($r = 0; $r < 16; $r++) {
        $path1 = $path[$r] . "/" . $name[$r];
        $picno = $picnoarray[$r];
        $query = mysql_query("INSERT INTO `decoy` (`username`, `picno`, `type`) VALUES ('{$username}', '{$picno}', {$type})");
    }
}

        <h4><b>Stage 2/2</b></h4>
    	<center>
    	
    	<p><b>Please select an image in order to complete the registration phase</b></p>
    	<br> <br>
    	 

        <button class="refreshclass" name="refresh" id="refresh">Change set</button>
        <br></br>
    	<div name="details" id="details" border="0">
		<?php 
$category = $_SESSION['category'];
$categoryno = $_SESSION['categoryno'];
printpic($category);
// calls printpic function
//-------------------------------------------------------
require_once "shiftimage.php";
// Used to change image set
// Creates and Dispalys image buttons.
function printpic($category)
{
    $style = " margin=0px; background-color=transparent; border=none;";
    $styleimage = "120";
    $eventimage1 = "zoomin(this)";
    $eventimage2 = "zoomout(this)";
    $btnclass = "btnclass";
    $i = 0;
    $spa = 0;
    $m = 1;