943,724 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1205
  • PHP RSS
Jul 25th, 2008
0

Why for loop in javascript is reseting a PHP variable

Expand Post »
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.
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gargg321 is offline Offline
21 posts
since Jun 2008
Jul 25th, 2008
0

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

this is also done by using simple php and database queries...
why are you try to do this by java script????
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Running a script daily
Next Thread in PHP Forum Timeline: downloading an application from a site





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC