Why for loop in javascript is reseting a PHP variable

Reply

Join Date: Jun 2008
Posts: 21
Reputation: gargg321 is an unknown quantity at this point 
Solved Threads: 0
gargg321 gargg321 is offline Offline
Newbie Poster

Why for loop in javascript is reseting a PHP variable

 
0
  #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.
  1. var i,x=0;
  2. <?php $ind=0; ?>
  3. for(i=0;i< <?php echo $num ?>;i++)
  4. {
  5. alert(<?php echo $ind; ?>);
  6. if(fobj.username.value== <?php echo "\"".$uname[$ind]."\"";?>)
  7. {
  8. alert(<?php echo "\"".$uname[$ind]."\"";?>);
  9. x=x+1;
  10. alert("if");
  11. }
  12. alert("loop");
  13. <?php $ind++; ?>
  14. alert(<?php echo $ind;?>);
  15. }
  16. if(x>=1)
  17. {
  18. alert("Can't login. User Name has expired.");
  19. return false;
  20. }

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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

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

 
0
  #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????
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC