SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Non-Member wulf's Avatar
    Join Date
    Jul 2006
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    please help... simple php script wont work... timeout with no errors...

    Alright I'm having a huge problem... the system seems to timeout when I use an if statement inside a for statement seeking for a file which does exist...
    Its weird because when I echo it... it doesn't time out... only when I place it inside the if statement... talk about dumb. I've tried using variables as well as the full exntention.
    Code:
    $locate = $_GET['locate'];
    $item = $_GET['item'];
    $purchase = $_GET['purchase'];	
    	
    	for($i="1";$b==FALSE;$i++){
    		$file = "$finventory/$i.txt";
    		$filecheck = file_exists("$finventory/$i.txt");
    		if($filecheck){
    			$fopen = fopen($file, 'r');
    			$empty = $file[0];
    			fclose($fopen);
    			if($empty == 0){
    				$fopen = fopen($file, 'w');
    				$fwrite = fwrite($fopen, "$locate/$item/$purchase.txt");
    				$b = FALSE;	
    			}
    		}
    		$i++;
    	}

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's a forever loop. $b never is TRUE, and that's the only condition to exit the loop.
    Saul

  3. #3
    Non-Member wulf's Avatar
    Join Date
    Jul 2006
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but it timesout before that... it says the problem is the variable $filecheck... when I place it inside the if statement it keeps checking for it forever...

    well you guys see if you can figure it out for fun I already gave up on it. I used a do loop instead and got the same effect I was looking for.

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Location
    Atlantis
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does it say as a problem, if you receive an error message, let us know that. Also, $file is a string, what are you trying to do with $file[0] ?

  5. #5
    SitePoint Evangelist ldivinag's Avatar
    Join Date
    Jan 2005
    Location
    N37 33* W122 3*
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is it possible to

    $i++

    a variable when it is a string?
    leo d.

  6. #6
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ldivinag
    is it possible to

    $i++

    a variable when it is a string?
    Yes, it converts it to an integer and increments it. In this case $i is initiated as a string, that's absolutely unnecessary and only causes an extra conversion of the data type.
    Saul

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use var_dump() on all your variables at logical locations in your script.

    test and verify your conditonal statements.

    use error_reporting(E_ALL);

    you will find your problem. this is basic debugging and you really should learn how to do it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •