Reputation: 907
I cannot retrieve the $_GET['id']
nor $_GET['action']
from a form and input in this page:
<?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
Upvotes: 0
Views: 59
Reputation: 385
try adding action and id as hidden input fields with the values you need
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>";
}
Upvotes: 1