954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

using empty() with while loop gives maximum execution time error

Hello
I am trying to add a poll function to a forum. the adding forum has radio buttons which asks the user whether he wants to add a poll or not. If he chooses yes the questions and the answers will be added to the database. I have included five inputs for answers of the poll. since the user sometimes does not put answers in all of them (the poll he inserts has three options for example) so I included empty function as seen below in the code. However I am receiving an error that maximum execution time of of 30 seconds exceeded.

When I remove the empty function I do not receive this error, however all of the five answers will be inserted even if they did not contain any text.

Can someone help?
here is the script

if ($apt->post[pollcheck] == 1)
		{
$question = $apt->format_data($apt->post[pollq]);
$apt->query("INSERT INTO threadquestion (question,thread,userid) VALUES ('$question','$id','$userid')");

         $qid = $apt->insertid();
         $i = 1;
         while ($i <= 5)
         {
             $answer = $apt->format_data($polla[$i]);
			 if (!empty($answer)) {
             $apt->query("INSERT INTO threadanswers (quesid, text, results) VALUES ('$qid','$answer', '0')");
             $i = $i + 1;
			}
		}
		}
khr2003
Junior Poster in Training
64 posts since Dec 2008
Reputation Points: 10
Solved Threads: 1
 

$i = $i + 1;

Should be outside of the if. It is now not incremented, so you'll have an infinite loop.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

thanks a million!

khr2003
Junior Poster in Training
64 posts since Dec 2008
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You