Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP script suddenly stops

Options
  • 01-11-2009 7:20pm
    #1
    Registered Users Posts: 1,086 ✭✭✭


    I have been working constantly on one of my websites and when I previewed it on the server one day I realised some of the php pages don't display any output. One of the php pages displays only about half of the page and stops randomly in the middle of a "for" loop.

    When I comment out the "for" loop the script just finishes a few further lines down the code. I have no idea why this has happened.

    Anybody have any idea how I can fix this problem? My website is completely un-usable now.


Comments

  • Moderators, Music Moderators Posts: 23,361 Mod ✭✭✭✭feylya


    What's in the for loop?


  • Registered Users Posts: 1,086 ✭✭✭Peter B


    This is my for loop.
    <select name="minute"> 
            <?
    		for($i=0;$i<2;$i++)
    		{
    			$filler="";
    	  		$min = 	($i*5);
    			if(($min)<10)
    			{
    				$min = "0".$min;
    			}
    			if(isset($_POST['minute']))
    			{
    				$check_against = $_POST['minute'];	
    			} else {
    				$check_against = date("i");
    				$check_against = intval($check_against / 5)*5;
    			}
    			if($min == $check_against)
    			{
    				$filler = "selected ";
    			}
    		?><option value="<?	echo $min; ?>" <? echo $filler; ?>><? echo $min; ?></option>
            <?
    		}
    		?></select>(Mins)
    


  • Registered Users Posts: 2,793 ✭✭✭oeb


    Does it return any errors if error reporting is set to full?

    There is nothing wrong with that loop and I was able to get it running with very minor changes (Due to the fact that I have short tags switched off).

    Is it intended to only display 00 and 05 as possible choices? If not you need to change the condition of your loop to $i<12.

    Also, if you want to have the current time selected when there is no post value, and you wish to round it to the nearest 5 min the following will work better than what you have.
    [PHP]
    $check_against = round(date("i")/5)*5;
    [/PHP]

    If you look at the source output of your code is the rest of the content being output (For example, if you forget to close a tag or an inverted comma, it's possible that it is still being output, but just not rendered.

    Either way, we will need to see more code to see if we can track down the error for you.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Is it really random? Do the last entries outputted (or more likely the one just after that) have anything in common?

    It may not be your code - does this happen on your development server too or only on your live server?

    How long does it take your script to run? What is the script time-out value on the server? Do you get an error message? Are error messages enabled?


  • Registered Users Posts: 1,086 ✭✭✭Peter B


    I have found out the solution. Thanks very much for the help. As it turns out it was due to me having a shortcut function so I didn't have to write the mysql_real_escape_string() method each time.

    It was
    function mres($str)
    {
    	return mysql_real_escape_string($str);	
    }
    

    Only when I did a replace all occurrences of the text "mysql_real_escape_string" to "mres" it also changed to helper function changing it into an infinite recursive function. As below:-
    function mres($str)
    {
    	return mres($str);	
    }
    

    For some reason the code would continue in some cases and only display half the page and in other cases it would not display any output at all.

    Anyway thanks for all the help!:)


  • Advertisement
Advertisement