hmm... where to start?
First off the sequence of commands at the start of your script looks wrong:
$sql = "SELECT * FROM image WHERE image_id=$iid";
$iid = $_GET["iid"];
You're only assigning a value to $iid after you construct the sql query. This means that the query you send to sql is just SELECT * FROM image WHERE image_id=
Of course that's not a complete statement, so it won't execute, which is why $result doesn't contain a valid result resource afterwards.
The next problem I see is that, assuming you correct the above, you're doing nothing with the data you return from the query. You just continue to use $iid which by now you have set equal to one of the GET variables:
print "<img src=\"image_script.php?iid=$iid\">";
$iid++;
print "<a href=\"image_script.php?iid=$iid>\"Next</a>";
From what I can see, you need two separate scripts here:
show_image.php
This script would take an argument of $id, search the database for that image and display it. It could be that simple. The main thing here is that this just returns a gif/jpg - no html at all. (You could enhance it a little if you like so that for invalid values of $id, it would default to a "no such image" graphic. You could also enhance this so that it would only respond to queries where the referrer was one of your pages.)
show_image_page.php
This script would take an argument of $id, search the database for that image, and identify what the id of the "previous" and "next" images are. It would then build this page to contain "previous" and "next" links to itself with the apprpriate values for $id, and it would also call show_image.php in an <img> tag with the current value for $id to actually display the image somewhere on the page.
Does this help clarify at all?
J