Page 1 of 1

Error in code

Posted: Mon Jun 17, 2002 11:52 am
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;

Posted: Mon Jun 17, 2002 12:34 pm
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

Posted: Mon Jun 17, 2002 12:39 pm
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.