将变量从 href 传递到另一个 php 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5229735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:41:38  来源:igfitidea点击:

pass variable from href to another php page

phpmysql

提问by zerey

.I have this code:

.我有这个代码:

<a id="various3" href="picture.php?id=',$pid,'" title="'.$info.'"><img src="picture.php?id=',$pid,'" width="150" height="210"></a>

it passes the id to my picture.php where i use it on a query string.

它将 id 传递给我的picture.php,我在查询字符串中使用它。

$sql = sprintf("select pics, ext from `06-07` where id='%d'",$_GET['id']);

Is it possible to pass more than one variable using this method? because i would like to pass "dept" along with the "id". if it is then how?

是否可以使用此方法传递多个变量?因为我想通过“dept”和“id”。如果是那又如何?

I have tried this:

我试过这个:

<a id="various3" href="picture.php?id=',$pid,'&dept=',$dept,'" title="'.$info.'"><img src="picture.php?id=',$pid,'&dept=',$dept,'" width="150" height="210"></a> 

with matching

搭配

$sql = sprintf("select pics, ext from 06-07 where id='%d' AND dept='%s'", $_GET['id'], $_GET['dept']); but it doen't work. what's wrong?

回答by laxmi kalake

<a href="test.php?page_name=<?php echo $this_month; ?>">

access this on another page by get method:

通过 get 方法在另一个页面上访问它:

$file_name = $_GET['page_name'];

回答by Ikke

You can chain get parameters with the & sign like this:

您可以使用 & 符号链接获取参数,如下所示:

index.php?id=1&depth=2

回答by naiquevin

Yes it is possible to pass more than 1 parameters in the get request using something like

是的,可以使用类似的东西在 get 请求中传递 1 个以上的参数

picture.php?id=1&dept=xyx&...

But note that whatever you pass this way will be visible in the browser, so don't use this method to pass something that the user should not know.

但是请注意,您通过这种方式传递的任何内容都将在浏览器中可见,因此不要使用此方法传递用户不应该知道的内容。

Also, is there a typo in the code ? Instead of picture.php?id=',$pid,', it should be picture.php?id=' . $pid . 'or picture.php?id=<?php echo $pid; ?>right ?

另外,代码中是否有错别字?相反picture.php?id=',$pid,',应该picture.php?id=' . $pid . '还是picture.php?id=<?php echo $pid; ?>对的?

回答by h00ligan

Based on your examples the query string is going to be pretty strange.

根据您的示例,查询字符串将非常奇怪。

First off, you're trying to use single quotes around the variable values.

首先,您尝试在变量值周围使用单引号。

Second, is the line a part of a print/echo statement? As it is now it seems you're not printing the PHP variables at all so you'll most likely just get the variable name as part of the url.

其次,该行是打印/回显语句的一部分吗?就像现在一样,您似乎根本没有打印 PHP 变量,因此您很可能只是将变量名称作为 url 的一部分。

Assuming the example line you've given is NOT a part of a print/echo statement:

假设您给出的示例行不是打印/回显语句的一部分:

<a id="various3" href="picture.php?id=<?= $pid ?>&dept=<?= $dept ?>" title="<?= $info ?>"><img src="picture.php?id=<?= $pid ?>&dept=<?= $dept ?>" width="150" height="210"></a>

If the example line is a part of a print/echo statement:

如果示例行是打印/回显语句的一部分:

print '<a id="various3" href="picture.php?id='.$pid.'&dept='.$dept.'" title="'.$info.'"><img src="picture.php?id='.$pid.'&dept='.$dept.'" width="150" height="210"></a>';