Error in code

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
toppac
Forum Commoner
Posts: 29
Joined: Fri Jun 14, 2002 10:44 am

Error in code

Post by toppac »

can someone glance over this code. It seems to be giving me an infinite loop and I cant figure out why.

Code: Select all

while (($_POST&#1111;$sku] != NULL) AND ($counter <=5) AND ($error&#1111;'code'] == "")) &#123;
		
		$query = "INSERT INTO tvproducts (prodgroup, sku, prodType, tvflag, tvdate, site) VALUES ('$prodGroup', '$_POST&#1111;$sku]', '$_POST&#1111;$prodType]', 1, SYSDATE, '$_POST&#1111;$site]')";
		$statement = OCIParse($connect, $query);
		if (@OCIExecute($statement, OCI_DEFAULT)) &#123;
			
			$counter++; 
			$sku = 'sku'.$counter;
			$prodType = 'prodType'.$counter;
			$site = 'site'.$counter;
			$error = OCIError($statement);
		&#125;
	&#125;
User avatar
amnuts
Forum Newbie
Posts: 16
Joined: Fri Jun 14, 2002 1:48 pm
Contact:

Post by amnuts »

Hi,

It's because the conditions in the while loop are never being exceeded. Eg, $counter is always <= 5, $error['code'] is always "" and $_POST[$sku] is never null.

Try moving the $counter++ out of the if block.

Andy
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post by Galahad »

You could try doing this:

Code: Select all

while ((isset($_POST&#1111;$sku]) AND ($counter <=5) AND ($error&#1111;'code'] == "")) &#123;
If that doesn't work, I think you may have problems with your error handling. I've never tried the OCI functions before, so I don't know how they really work. However, it seems that if OCIExecute fails, then $error is not updated. The next time through the loop, it would still be "", at least I think it would be. Try echoing $error every time to see what it's doing. Is there any reason why you aren't using the error reporting on OCIExecute? Perhaps that would be a better way to do it. I guess this still doesn't explain why the other two conditions are failing. Do you know that $counter is getting incremented? Try echoing $counter in the loop to see if you actually do get an infinite loop. If not, perhaps it is hanging trying to connect to the database. Well, those are my suggestions, I hope it helps.
Post Reply