954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Why for loop in javascript is reseting a PHP variable

Hi

I am in a bit of fix. I am developing a module in PHP where I am using javascripts to validate the data entered by the user. Now the problem is that I am firing a query to the database through PHP and hence storing its results in PHP variables. To validate a form I have to check whether the data entered by the user matches with database or not.

var i,x=0;
	<?php $ind=0; ?>
	for(i=0;i< <?php echo $num ?>;i++) 
	{
		alert(<?php echo $ind; ?>);
		if(fobj.username.value== <?php echo "\"".$uname[$ind]."\"";?>)
		{
			alert(<?php echo "\"".$uname[$ind]."\"";?>);
			x=x+1;
			alert("if");
		}	
		alert("loop");
		<?php $ind++; ?>
		alert(<?php echo $ind;?>);
	}
	if(x>=1)
	{
		alert("Can't login. User Name has expired.");
		return false;
	}


The above given code is written in tags of javascript. Now what's happening is that variable $ind is reseting itself when the loop starts again. At the end of loop if it's value is 1 then it becomes 0 when it reiterates the loop again.

What's going on guys. How could I retain the value of $ind

gargg321
Newbie Poster
21 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

this is also done by using simple php and database queries...
why are you try to do this by java script????

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You