Reputation: 651
I'm trying to pass the path of an image ['guest'] from one page to another using a link. (I'm storing URLs of images in database) Can't seem to get the image to display, which is a bigger image of 'url'. I'm doing it this way so that I can have a larger image displayed in the target page (does_this_work.php) plus adding some other bits on the page too.
I'm still learning and can;t seem to see what I'm doing wrong. Any help appreciated,
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name) or die("cannot select DB");
$photo=mysql_query("SELECT * FROM `images` ORDER BY (ID = 11) DESC, RAND() LIMIT 7");
while($get_photo=mysql_fetch_array($photo)){ ?>
<div style="width:300px;">
<a href="does_this_work.php?big_image=$get_photo['guest']>" target=""><img src="<?
echo $get_photo['url']; ?>" title="">
</div>
<? } ?>
I then use the following code to try and display the array data in the target file
<?php
echo "this is the page where you get a larger picture of image on previous page, plus
further info";
$big_image = $_GET['guest'];
echo $big_image;
?>
Upvotes: 1
Views: 943
Reputation: 1515
There are several errors in your code. First of all, this is how you use $_GET and $_POST:
ex. site.php?argument=value
To retrieve the value of argument, you need this code in site.php:
//The variable must not necessarily be $value
$value = $_GET['argument'];
//Alt.
$value = $_POST['argument'];
Secondly (like the other answers tell you) you are missing a php-tag here:
<a href="does_this_work.php?big_image=$get_photo['guest']>" target=""><img src="<? echo $get_photo['url']; ?>" title="">
Instead it should be:
<a href="does_this_work.php?big_image=<?php echo $get_photo['guest']; ?>" target=""><img src="<?php echo $get_photo['url']; ?>" title="">
Now, in order to make that compatible with your second code, you need to change the argument sent to guest like this:
<a href="does_this_work.php?guest=<?php echo $get_photo['guest']; ?>" target=""><img src="<?php echo $get_photo['url']; ?>" title="">
OR change the $_GET['guest']; to $_GET['big_image'];
I think I got it all right..
Upvotes: 0
Reputation: 2872
You're missing an opening tag in here (And a closing semi colon, but that's not as problematic here):
<a href="does_this_work.php?big_image=$get_photo['guest'] ?>"
Change to:
<a href="does_this_work.php?big_image=<?= $get_photo['guest']; ?>"
Upvotes: 1
Reputation: 1958
<a href="does_this_work.php?big_image=$get_photo['guest'] ?>" target=""><img src="<?
echo $get_photo['url']; ?>" title="">
You are missing your php starting tags. This should read:
<a href="does_this_work.php?big_image=<? $get_photo['guest'] ?>" target=""><img src="<?
echo $get_photo['url']; ?>" title="">
Upvotes: 0