User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 401,449 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,942 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 157 | Replies: 1
Reply
Join Date: Jun 2008
Posts: 18
Reputation: gargg321 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
gargg321 gargg321 is offline Offline
Newbie Poster

Why for loop in javascript is reseting a PHP variable

  #1  
Jul 25th, 2008
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
Commitment is what transforms a promise into reality. It is the words that speak boldly of your intentions. And the actions which speak louder than the words. It is making the time when there is none. Commitment is the stuff character is made of; the power to change the face of things. It is the daily triumph of integrity over skepticism.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 534
Reputation: Shanti Chepuru is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 53
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is online now Online
Posting Pro

Re: Why for loop in javascript is reseting a PHP variable

  #2  
Jul 25th, 2008
this is also done by using simple php and database queries...
why are you try to do this by java script????
Champions Are Not SuperNatural,They Just Fought For One More Second When Every One Else Quit...Some times That One Second Of Effort Gives You The VICTORY...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 1:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC