Results 1 to 4 of 4

Thread: 'Page cannot be displayed' error when working with arrays

  1. #1

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    'Page cannot be displayed' error when working with arrays

    Hey, i am adding the ability for users to attach images to their posts on my forum.. Now... they can attach them fine, they attach them one at a time whilst writing the post and it gives a list of currently attached images. Now what i want to do is add the ability to unattach images.

    The trouble is, i'm getting a 'page cannot be displayed' error when removing the image from an array. The address in the address bar is fine, no problem with that so i cant work out why i'm getting the error. ForumDiscardImage.php is the actual page that apparently can't be displayed. Anyway, heres the code that actually constructs the link:
    Code:
    if ($_GET['imagename']!="") { 
        $iname = $_GET['imagename']; 
        if (!isset($_SESSION['currentfiles'])) { 
            $_SESSION['currentfiles'] = $iname; 
            $attachedfiles = "<li>".$iname."<font size='-1'> - <a href='ForumDiscardImage.php?arraynumber=0&threadid=$threadid&sectionid=$sectid'>Discard Image</a></font></li>"; 
        }else{ 
            $sesh = $_SESSION['currentfiles']; 
            $exploded1 = explode(",", $sesh); 
            $inarray1 = count($exploded1)-1; 
                if ($exploded1[$inarray1]!=$iname) { 
                    $sesh = $sesh.",".$iname; 
                } 
            $_SESSION['currentfiles'] = $sesh; 
            $exploded = explode(",", $sesh); 
            $inarray = count($exploded); 
                if ($inarray==6) { 
                    $imglink = "ForumMaximum.php"; 
                }else{ 
                    $imglink = "ForumPostImage.php?threadid=$threadid&sectionid=$sectid"; 
                } 
                for ($i=0; $i<count($exploded); $i++) { 
                    $attachedfiles .= "<li>".$exploded[$i]."<font size='-1'> - <a href='ForumDiscardImage.php?arraynumber=$i&threadid=$threadid&sectionid=$sectid'>Discard Image</a></font></li>"; 
                } 
        } 
        unset($iname, $inarray, $exploded, $exploded1, $inarray1, $sesh, $i); 
        $attachmessage = "<b>Images currently attached:</b><br><br> <i>".$attachedfiles."</i><br>"; 
    }
    And heres the code that supposed to remove the image number from the array but its saying 'page cannot be displayed' instead:
    Code:
    $arraynumber = $_GET['arraynumber']; 
    $tfid = $_GET['threadid']; 
    $sfid = $_GET['sectionid']; 
    $sesh = $_SESSION['currentfiles']; 
    $exploded = explode(",", $sesh); 
    $inarray = count($exploded); 
        if ($inarray==1) { 
            unset($_SESSION['currentfiles']); 
            unset($arraynumber, $sesh, $exploded, $inarray); 
            header("location: ForumNewReply.php?threadid=$tfid&sectionid=$sfid"); 
            exit(); 
        }else{ 
            for ($i=0; $i<$arraynumber; $i++) { 
                $sess1 .= $exploded[$i].","; 
            } 
            for ($i=$arraynumber+1; $i=$inarray-1; $i++) { 
                $sess2 .= $exploded[$i].","; 
            } 
            $finalsess = $sess1.$sess2; 
            $finalsesh = substr_replace($finalsess, "", -1); 
            $_SESSION['currentfiles'] = $finalsesh; 
            $exploded1 = explode(",", $finalsesh); 
            $inarray1 = count($exploded1)-1; 
            $lastitem = $exloded1[$inarray1]; 
            unset($arraynumber, $sesh, $exploded, $inarray, $sess1, $sess2, $finalsess, $finalsesh, $exploded1, $inarray1, $i); 
            header("location: ForumNewReply.php?threadid=$tfid&sectionid=$sfid&imagename=$lastitem"); 
            exit(); 
    }
    I've been studying this for hours and just cant work out why i'd be getting this error Can anyone PLEASE help?? Many thanks,

    BIOSTALL

  2. #2

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    Re: 'Page cannot be displayed' error when working with arrays

    Whoops, would a mod mind moving this to the PHP forum please?? thanks.

    BIOSTALL

  3. #3

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: 'Page cannot be displayed' error when working with arrays

    Firstly, the error you are getting is caused by your second loop. You have made it an infinite loop which never exits. = should ==
    Code:
    for ($i=$arraynumber+1; $i=$inarray-1; $i++) {
    Invariably PHP will crash with some kind of exception and the server will return a 500 HTTP status code. The reason you are getting the "Page Cannot be Displayed" error is because you have friendly HTTP errors turned on in Internet Explorer. You can turn these off by going to Internet Options --> Advanced and un-checking the "Display Friendly HTTP Errors" box.

    Secondly, I would strongly advise against using variables from the $_GET array to set the exit condition of the loop. If a user were to enter -1 in the arraynumber field then they would recreate the same error you are getting now. It is better to use the value returned by count().
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width