|
-
Aug 3rd, 2005, 03:00 PM
#1
Thread Starter
Addicted Member
'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§ionid=$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§ionid=$sectid";
}
for ($i=0; $i<count($exploded); $i++) {
$attachedfiles .= "<li>".$exploded[$i]."<font size='-1'> - <a href='ForumDiscardImage.php?arraynumber=$i&threadid=$threadid§ionid=$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§ionid=$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§ionid=$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
-
Aug 3rd, 2005, 04:04 PM
#2
Thread Starter
Addicted Member
Re: 'Page cannot be displayed' error when working with arrays
Whoops, would a mod mind moving this to the PHP forum please?? thanks.
BIOSTALL
-
Aug 5th, 2005, 01:39 PM
#3
Re: 'Page cannot be displayed' error when working with arrays
-
Aug 14th, 2005, 12:35 PM
#4
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().
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|