Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在url中获取类别ID_Php - Fatal编程技术网

Php 在url中获取类别ID

Php 在url中获取类别ID,php,Php,我在互联网上找不到任何关于在url中获取类别id的信息,所以我在这里发布 我想要这样一个url:localhost/index.php&cat=1,当我按下提交按钮时 我使用以下代码: <form method="post" id="categories"> <select name="category"> <option value="">Select a category</option> <?php getCats(); ?> &

我在互联网上找不到任何关于在url中获取类别id的信息,所以我在这里发布

我想要这样一个url:
localhost/index.php&cat=1
,当我按下提交按钮时

我使用以下代码:

<form method="post" id="categories">
<select name="category">
<option value="">Select a category</option>
<?php
getCats();
?>
</select>
<button type="submit" form="categories" value="Submit">Submit</button>
</form>

在这种情况下可以使用
表单操作=

您最需要提醒的是以下两个技巧:

1) 只能访问GET方法上的查询字符串

2) 查询字符串从开始,如果参数多于一个,则使用&

在您的问题中,您使用以下内容:

localhost/index.php&cat=1

但它必须是:

localhost/index.php?cat=1&name=blah

如果您现在使用此技巧,您可以在php代码中获得如下数据:

$cat = $_GET["cat"]; //will be '1'
$name = $_GET["name"]; // will be 'blah'

方法
method=“post”
to method=“get”…请先学习如何编码。你在回音
  • 而没有
      标签。在标签中回音
    • 而不是@devpro:因为标签的缘故,这不起作用为什么你需要选择框?你可以选择一个select或ul li
      $cat = $_GET["cat"]; //will be '1'
      $name = $_GET["name"]; // will be 'blah'