使用PHP中的超链接传递数据


passing data using hyperlink in PHP

我正试图使用链接将图像['guest']的路径从一个页面传递到另一个页面。(我正在数据库中存储图像的URL)似乎无法显示图像,这是一个较大的"url"图像。我这样做是为了在目标页面(doe_his_work.php)中显示更大的图像,同时在页面上添加一些其他位。

我还在学习,而且可以;I don’我好像没看出我做错了什么。感谢任何帮助,

<?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>
 <? } ?>

然后,我使用以下代码尝试在目标文件中显示阵列数据

<?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;
?>

这里缺少一个开始标记(还有一个结束分号,但这里没有问题):

<a href="does_this_work.php?big_image=$get_photo['guest'] ?>"

更改为:

<a href="does_this_work.php?big_image=<?= $get_photo['guest']; ?>"

您的代码中有几个错误。首先,这就是使用$_GET和$_POST:的方式

前任。site.php?argument=值

要检索参数的值,您需要在site.php中输入以下代码:

//The variable must not necessarily be $value
$value = $_GET['argument'];
//Alt.
$value = $_POST['argument'];

其次(就像其他答案告诉你的那样)你在这里缺少一个php标签:

<a href="does_this_work.php?big_image=$get_photo['guest']>" target=""><img src="<? echo $get_photo['url']; ?>" title="">

相反,它应该是:

<a href="does_this_work.php?big_image=<?php echo $get_photo['guest']; ?>" target=""><img src="<?php echo $get_photo['url']; ?>" title="">

现在,为了使其与您的第二个代码兼容,您需要更改发送给来宾的参数,如下所示:

<a href="does_this_work.php?guest=<?php echo $get_photo['guest']; ?>" target=""><img src="<?php echo $get_photo['url']; ?>" title="">

或者更改$_GET['guest'];至$_GET['big_image'];

我想我做得很好。。

<a href="does_this_work.php?big_image=$get_photo['guest'] ?>" target=""><img src="<?     
echo $get_photo['url']; ?>" title="">

您缺少php起始标记。这应该是:

<a href="does_this_work.php?big_image=<? $get_photo['guest'] ?>" target=""><img src="<?     
echo $get_photo['url']; ?>" title="">