Passing Hidden Variables in an array
Posted: Mon Nov 02, 2009 9:45 am
Hi, im trying to pass a number of variables with the same name through a form in the following format:
cart.php?action=add&id=20,24&q=1,2
It's a product page and i'm trying to add multiple products to a cart with one button, cart side if i enter the following example in the browser i can explode the array and add the product so i just need to be able to send the correct url.
The page code is as follows:
<?php
$sql = 'SELECT * FROM products WHERE price = 122.33 ORDER BY id';
$result = $db->query($sql);
$output[] = '<form action="cart.php?action=add" method="GET">';
$output[] = '<input type="hidden" name="action" value="add">';
$id = implode(',', $_GET['id']);
$q = implode(',', $_GET['q']);
$output[] = '<input type="hidden" name="id" value="'.$id.'">';
$output[] = '<ul>';
while ($row = $result->fetch()) {
$output[] = '<li>'.$row['name'].' <br> '.$row['code'].' £'.$row['price'].'<input name="q" type="text" value="1" size="3" maxlength="3" class="input" /></li>';
}
$output[] = '</ul>';
$output[] = '<input type="submit" value="Add to Quotation" class="button" />';
$output[] = '</form>';
echo join('',$output);
?>
Thanks J
cart.php?action=add&id=20,24&q=1,2
It's a product page and i'm trying to add multiple products to a cart with one button, cart side if i enter the following example in the browser i can explode the array and add the product so i just need to be able to send the correct url.
The page code is as follows:
<?php
$sql = 'SELECT * FROM products WHERE price = 122.33 ORDER BY id';
$result = $db->query($sql);
$output[] = '<form action="cart.php?action=add" method="GET">';
$output[] = '<input type="hidden" name="action" value="add">';
$id = implode(',', $_GET['id']);
$q = implode(',', $_GET['q']);
$output[] = '<input type="hidden" name="id" value="'.$id.'">';
$output[] = '<ul>';
while ($row = $result->fetch()) {
$output[] = '<li>'.$row['name'].' <br> '.$row['code'].' £'.$row['price'].'<input name="q" type="text" value="1" size="3" maxlength="3" class="input" /></li>';
}
$output[] = '</ul>';
$output[] = '<input type="submit" value="Add to Quotation" class="button" />';
$output[] = '</form>';
echo join('',$output);
?>
Thanks J