[RESOLVED] SQL image viewer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Serbaside
Forum Newbie
Posts: 5
Joined: Sat Dec 03, 2005 6:49 pm

[RESOLVED] SQL image viewer

Post by Serbaside »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I am having this problem creating a image viewer that uses a MySQL database

Browser side:

Code: Select all

<head>
...
<?php include ("content.php"); ?>
</head>

<body>
...
	<td width="420" bgcolor="#E5E5E5" align="center">
	<?php	 	
	echo "<img src=gallery/$number.jpg>";
   	echo "<br> $name <br> $created <br> $height x $length x $width";
   ?>
</td>
    <td width="40" bgcolor="#E5E5E5" align="left">
		<form action="content.php">
			<input type="hidden" name="currentrow" value="<?php echo $counter ?>" />
			<input type="submit" name="submit" value=">" />
			<input type="submit" name="submit" value="<" />
		</form>
	</td>
...
</body>
Processing side:

Code: Select all

$counter=1;

if($_GET['submit']=='>')
{
  $counter = ($_GET['currentrow']+1);
}
elseif($_GET['submit']=='<')
{
  $counter = $_GET['currentrow']-1;
} 


$query="select * from gallery where number=$counter";

$result = mysql_query($query);
$r=mysql_fetch_array($result);

   $number=$r["number"];
   $name=$r["name"];
   $created=$r["created"];
   $height=$r["height"];
   $length=$r["length"];
   $width=$r["width"];
   $type=$r["type"];

header("location:work.php");
The form submits correctly and the query advance to the next record but the problems happens when it reloads the browser. Somehow the browser does not get the new field variabled...If you wish to view the actual site its here (http://www.namelesscreations.com/new/work.php)

Any suggestions would great, Jeff McKinney


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Last edited by Serbaside on Sun Dec 04, 2005 5:08 pm, edited 1 time in total.
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post by William »

Have you tried using the method GET instead of POST?
Serbaside
Forum Newbie
Posts: 5
Joined: Sat Dec 03, 2005 6:49 pm

Post by Serbaside »

Same results.

When I return to the orgianl page after process do all the variables get sent with it?

I did a bit more changing and fixed the header issue by removing the include statement...it was getting caught in a loop.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

First things first,

Code: Select all

<form action="content.php">
you've never set a method in your form,

Code: Select all

<form action="content.php" method="GET">
Also, why are you using a form to process this? Why not simply use links?

The problem with using the form on a refresh is most likely you'll get that stupid "There was a post request, refresh post request?" or whatever it is, but from what I can tell your not even getting that. The refresh seems to be wiping your post data, therefor making your current code useless. The best course of action would be to pass the current image id variable along the query string.. so you should have something along the lines of

http://domain.com/imageViewer.php?id=4

and then something along the lines of

Code: Select all

echo '<a href="http://domain.com/imageViewer.php?id='.(intval($_GET['id']) + 1).'">Next</a>';
Theres obviously much more involved, but I hope you get the point.
Last edited by John Cartwright on Sun Dec 04, 2005 4:00 pm, edited 2 times in total.
Serbaside
Forum Newbie
Posts: 5
Joined: Sat Dec 03, 2005 6:49 pm

Post by Serbaside »

I'm going to go with your suggestion JCart and just generate a list of links from the database.

Even with the GET or POST the same results happen.
Post Reply