[英]Unable to get $_GET values from form
I cannot retrieve the $_GET['id']
nor $_GET['action']
from a form and input in this page: 我无法从表单中检索$_GET['id']
或$_GET['action']
并在此页面中输入:
<?php
include "common.php";
var_dump($_GET['quantity']);
var_dump($_GET['action']);
var_dump($_GET['id']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>es6.1.6</title>
<style type="text/css">
input {
margin: 10px;
}
</style>
</head>
<body>
<ul>
<?php
for($i=1; $i<=sizeof($names); $i++) {
echo "<form method='get' action='shop.php?action=add&id=$i'>";
echo "<li><a href='description.php?item=$i'> ",$names[$i],"</a></li>";
echo "<input type='number' name='quantity'>";
echo "</form>";
}
?>
</ul>
<br><br>
<form action="summary.php">
<input type="submit" value="Add to cart">
</form>
</body>
</html>
only $_GET['quantity']
will be set after inserting a number and pressing Enter into any input form 插入数字并在任何输入形式中按Enter后,仅设置$_GET['quantity']
try adding action and id as hidden input fields with the values you need 尝试将action和id添加为具有所需值的隐藏输入字段
edit: change your code to look like this: 编辑:更改您的代码,如下所示:
for($i=1; $i<=sizeof($names); $i++) {
echo "<form method='get' action='shop.php'>";
echo "<li><a href='description.php?item=$i'> ",$names[$i],"</a></li>";
echo "<input type='number' name='quantity'>";
echo "<input type='hidden' name='action' value='add'>";
echo "<input type='hidden' name='id' value='" . $i . "'>";
echo "</form>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.