Php 在url中获取类别ID
我在互联网上找不到任何关于在url中获取类别id的信息,所以我在这里发布 我想要这样一个url: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(); ?> &
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'