while loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
krraleigh
Forum Commoner
Posts: 86
Joined: Tue Jul 17, 2007 2:52 pm

while loop

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
boo
Forum Commoner
Posts: 42
Joined: Mon Jul 02, 2007 11:30 am
Location: NY

Post by boo »

I would insert the echo within the while to see if it is truly looping or not
krraleigh
Forum Commoner
Posts: 86
Joined: Tue Jul 17, 2007 2:52 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
krraleigh
Forum Commoner
Posts: 86
Joined: Tue Jul 17, 2007 2:52 pm

Post by krraleigh »

That took care of the problem.
wonder why it worked before?
Globals are off.

Weird :wink:
Kevin
Post Reply