Page 1 of 1

while loop

Posted: Mon Jul 30, 2007 8:47 pm
by krraleigh
Can anyone tell me what is supposed to terminate this while loop.
If I am right, as it stands it just keep running.

Code: Select all

while($info = mysql_fetch_array( $check )) {
 			$fName = $info['fName'];
		}
What I think is supposed to happen is that when the the length of the array is reached the while terminates.

As it stands I never reach my echo statement:

Code: Select all

if (empty($check2)) {	  
	  $_SESSION['SES_loginErr'] = "Your email address was not found in the database, please try again!";
	  header('Location: forgotPass.php');
	  exit;
  } else {
  		
		while($info = mysql_fetch_array( $check )) {
 			$fName = $info['fName'];
		}
			
		echo "hello";
		exit;
insight appreciated
thank you
Kevin

Posted: Mon Jul 30, 2007 8:53 pm
by John Cartwright
The loop will terminate when it has iterated over every row in your result set.

Code: Select all

echo mysql_num_rows($check);
will tell you how many rows you've queried.

Posted: Mon Jul 30, 2007 8:59 pm
by boo
I would insert the echo within the while to see if it is truly looping or not

Posted: Mon Jul 30, 2007 10:06 pm
by krraleigh
I found the problem, but I don't think I can do anything about it.

When I use the mouse to click on the submit button all is well.
However when I use the enter key to fire the submit button it
fails to process anything. It just clears the field.

Any ideas?? :?

Kevin

Posted: Mon Jul 30, 2007 10:24 pm
by feyd
Your code relies on the submit button being in the submission data, which it, apparently, is not. Look for another form element or detect the submission through other means such as $_SERVER['REQUEST_METHOD'].

Also be aware that your code may rely on register_globals being on too, which is even worse because it can be turned off. For more on how to remove this dependency, consult the search features of the forum.

Posted: Mon Jul 30, 2007 10:54 pm
by krraleigh
That took care of the problem.
wonder why it worked before?
Globals are off.

Weird :wink:
Kevin