alert messages interupting the session variable
<p>I have a experiment which displays 200 images without repetition(image slide show for three seconds),The images are obtained from the image database(contains 200 images each image contains 4 fields imgname,image,imagetype,imgid ),depending on the imgid responses are generated in the form of alert messages.At the end of each image display(after three seconds),alert message is displayed this alert message is the system response to the image displayed, there is a button which when clicked(must be clicked within 3 seconds) displays the user response to the image displayed.These responses get stored in the another database called ResponseThreeSecSlideshow .I'm refreshing the page after every three seconds,I'm maintaining the session variable called imgDisplayCount ($_SESSION ['imgDisplay Count']) which gets incremented on every refresh.If this variable reaches 200 I'm redirecting the page to another page(EndofExperiment.php).</p>

<p>I'm checking the value of imgDisplayCount if it is &lt;=201 then I'm redirecting the page else I'm refreshing the page.</p>

<p>here is my code </p>

<hr>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;?php 
session_start();
$_SESSION['imageDispCnt'] = $_SESSION['imageDispCnt']+1;
//query to generate random image from database
while ($row = mysql_fetch_array($result))
{
    $img = $imagepath.$row['img_name'];
    $id = $row['imageid'];
    $img_id = $row['img_id'];
}

if($_SESSION['imageDispCnt'] &gt;= 201)
{
    //unset($_SESSION['sid']); 
    $_SESSION['imageDispCnt'] = 0;
    header('Location:endofexperiment.php');

}
else
{
    echo "&lt;meta http-equiv=\"refresh\" content=\"4\" /&gt;";
}

?&gt;
&lt;/head&gt;
&lt;body onload="display()"&gt;//displaying the image
&lt;center&gt;&lt;img src="&lt;?php echo $img ?&gt;" id="&lt;?php echo $id?&gt;" name="r_img" /&gt;
&lt;form name=myForm&gt;
&lt;div&gt;&lt;input type="button" name="btn1" value="Stop bag"
    onclick="btn_click()" /&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;/center&gt;
&lt;script&gt;

var flag = 1;
var s;
var sec;
var d;
var milisec = 0;
var seconds = 0;
var imgname;
var count;


imgname = '&lt;?php echo $img ?&gt;';
imgid = '&lt;?php echo $img_id?&gt;';
count= '&lt;?php echo $_SESSION['imageDispCnt']?&gt;';
if(flag == 1)
setTimeout("msg(flag)",3000);
function msg(flag)
{
    document.myForm.btn1.disabled = true;
    //alert message
        //pop function to call window.open method to record values to the database
    }
    return 1;
}

function btn_click()
{
    document.myForm.btn1.disabled = true;
    flag = 0;
    //alertmessage
        //pop function to call window.open method to record values to the database

}



&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>My problem is when I comment the alert messages.Everything is working fine.I'm getting 200 random images without any repetition, I'm storing the imgDisplayCount variable in ResponseThreeSecSlideshow database this variable starts from 1 and ends at 200 for the first image display imgDisplayCount is 1 for 2nd images increments by 1 and so on till 200.
But when I uncomment the alert messages, imgDisplayCount is recorded as 2 for the first image and when I click the button the imgDisplayCount value doesn't get incremented and when I don't click the button, alert msg is displayed at end of 3 seconds and imgDisplayCount increments twice.Only 199 images are getting stored in the table with some repeated images.To Solve this I took the imgDisplayCount and passed it along the query string in window.open() method. So now the imgDisplayCount starts from 1 and ends at 200.</p>

<p>I ran the experiment without any button click and response in the form of alert message is generated for every 3 seconds.I Still get Duplicate images.</p>

<p>I have provided the ResponseThreeSecSlideshow data (only duplicate images)</p>

<p>ImgDispCount  ID         SID     Imagename      Response  Rec_Time              img_id 
179       11310 1481    bag019.jpg  3    2011-03-22 11:16:39    019<br>
180       11311 1481    bag019.jpg  3    2011-03-22 11:16:42    019 
191       11322 1481    bag076.jpg  3    2011-03-22 11:18:58    076<br>
192           11323 1481    bag076.jpg  3    2011-03-22 11:19:02    076                 </p>

<p>I'm facing hard time figuring this out.I would be great help for me if some tells me were I went wrong.</p>

<p>Thanks</p>

<p>Shruti</p>
