rondog Posted April 26, 2008 Share Posted April 26, 2008 Ok I made a for loop and all of a sudden this server I am working on is giving me this error: Fatal error: Maximum execution time of 30 seconds exceeded in C:\Inetpub\vhosts\drewestate.com\httpdocs\new\2008\galleryeditor.php on line 32 <?php include 'connect.php'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php if(isset($_GET['action'])) { switch($_GET['action']) { case "edit": if(isset($_GET['id'])) { $query = mysql_query("SELECT * FROM de_images WHERE galleryid = '".$_GET['id']."'") or die(mysql_error()); $namequery = mysql_query("SELECT galleryName FROM de_galleries WHERE id = '".$_GET['id']."'") or die(mysql_error()); $name = mysql_fetch_row($namequery); $content = "<fieldset><legend>Editing the \"$name[0]\" Gallery.</legend>\n"; $content .= "<form method=\"post\">\n"; $count = 0; while($row = mysql_fetch_array($query)) { $count += 1; $content .= "<img src=\"gallery/$row[image]\" width=\"50%\" height=\"50%\"/><br>\n"; $content .= "<input type=\"text\" name=\"caption$count\"value=\"$row[caption]\" /><br><br>\n\n"; } $content .= "<input type=\"submit\" name=\"save\" value=\"Save Changes\" />\n</form>\n"; $content .= "</fieldset>"; if(isset($_POST['save'])) { $captions = array(); for($i = 0;i<$count;$i++) { array_push($captions,$_POST['caption$i'); } print_r($captions); } } else { $query = mysql_query("SELECT * FROM de_galleries") or die(mysql_error()); $content = "<fieldset><legend>Select a gallery to edit</legend>"; while($row = mysql_fetch_array($query)) { $content .= "<img src=\"gallery/$row[thumbnail]\" /><br>\n"; $content .= "<a href=\"?action=edit&id=$row[id]\">$row[galleryName]</a><br>\n"; } $content .= "</fieldset>"; } break; case "add": $content = "add a gallery."; break; } } ?> <table width="500" border="0" align="center"> <tr> <td><img src="images/drew-estate-logo-blue1.gif" alt="" width="100" height="100" /></td> </tr> <tr> <td><a href="?action=edit">Edit Gallery</a> | <a href="?action=add">Add Gallery</a></td> </tr> <tr> <td><?php echo $content; ?></td> </tr> </table> </body> </html> basically what I am doing here is outputting N number of images depending on whats in the DB. My for loop is to post the caption input text fields. The reason I am using a loop is because the same number of input fields aren't always the same so I want to store them into an array and then use that array to insert data into the DB. What do you think the problem is? Also I labeled line 32 so you can see it. Link to comment https://forums.phpfreaks.com/topic/103073-solved-maximum-execution-time-of-30-seconds-exceeded/ Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 if $count is 0, $i will never be less than it, thus an infinite loop. i'd check the value of $count. Link to comment https://forums.phpfreaks.com/topic/103073-solved-maximum-execution-time-of-30-seconds-exceeded/#findComment-527933 Share on other sites More sharing options...
darkfreaks Posted April 26, 2008 Share Posted April 26, 2008 our statement in the for one of youe $i's is not a variable for($i = 0;i<$count;$i++) { needs to be: for($i = 0;$i<$count;$i++) { also change $count= 0; to $count= count($variable); Link to comment https://forums.phpfreaks.com/topic/103073-solved-maximum-execution-time-of-30-seconds-exceeded/#findComment-527934 Share on other sites More sharing options...
rondog Posted April 26, 2008 Author Share Posted April 26, 2008 ahhh my bad I didnt see that..that seemed to work..thanks Link to comment https://forums.phpfreaks.com/topic/103073-solved-maximum-execution-time-of-30-seconds-exceeded/#findComment-527937 Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 good catch, i didn't see that either. Link to comment https://forums.phpfreaks.com/topic/103073-solved-maximum-execution-time-of-30-seconds-exceeded/#findComment-527938 Share on other sites More sharing options...
darkfreaks Posted April 26, 2008 Share Posted April 26, 2008 no problem sometimes it is a simple sntax error solved Link to comment https://forums.phpfreaks.com/topic/103073-solved-maximum-execution-time-of-30-seconds-exceeded/#findComment-527939 Share on other sites More sharing options...
rondog Posted April 26, 2008 Author Share Posted April 26, 2008 rather than making another topic, I figured I would ask here..I need to post numerous text fields called "caption0","caption1","caption2" etc...that was the reason I used a for loop. I tried: for($i = 0;$i<$count;$i++) { $cap = $_POST['caption'+$i]; array_push($captions,$cap); } AND for($i = 0;$i<$count;$i++) { $cap = $_POST['caption$i']; array_push($captions,$cap); } and neither have worked..what should i do? Link to comment https://forums.phpfreaks.com/topic/103073-solved-maximum-execution-time-of-30-seconds-exceeded/#findComment-527944 Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 $cap = $_POST['caption'.$i]; Link to comment https://forums.phpfreaks.com/topic/103073-solved-maximum-execution-time-of-30-seconds-exceeded/#findComment-527946 Share on other sites More sharing options...
rondog Posted April 26, 2008 Author Share Posted April 26, 2008 $cap = $_POST['caption'.$i]; yep..should have known that too..i think im a little slow today..thank you for the help. Link to comment https://forums.phpfreaks.com/topic/103073-solved-maximum-execution-time-of-30-seconds-exceeded/#findComment-527951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.