I fetch information from MySQL and putput a form on a web page. This informaiton is part of a web shop, and what is displayed is a list of items ordered by a customer. The idea was to output three "arrays" (like price[]) so when the form is submitted I get a post array back. However this only works for one of the three arrays I want, and I cannot figure out why.
Here's the code:
<?php
# Fetch product ID and count
$mysqli = new mysqli('localhost', 'user', 'pass', 'db');
$stmt = $mysqli->prepare("SELECT pid, count FROM orders_row WHERE oid = ?");
$stmt->bind_param("i", $_GET['oid']);
$stmt->bind_result($pid, $count);
$stmt->execute();
while($stmt->fetch())
{
# Fetch more info about each product
$mysqli2 = new mysqli('localhost', 'user', 'pass', 'db');
$stmt2 = $mysqli2->prepare("SELECT price, stock, title, orginal_no FROM product_products WHERE pid = ?");
$stmt2->bind_param("i", $pid);
$stmt2->bind_result($price, $stock, $title, $orginal_no);
$stmt2->execute();
$stmt2->fetch();
$stmt2->close();
$mysqli2->close();
# We will need pid[] later...
echo "<input type=\"hidden\" name=\"pid[]\" value=\"".$pid."\" />";
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"checkboxpid[]\" value=\"".$pid."\"/></td>";
echo "<td>".$pid."</td>";
echo "<td>".$orginal_no."</td>";
echo "<td>".$title."</td>";
echo "<td><input type=\"text\" name=\"count[]\" value=\"".$count."\" style=\"width: 2em\"/></td>";
echo "<td>".$stock."</td>";
echo "<td><input type=\"text\" name=\"price[]\" value=\"".addVAT($price)."\" style=\"width: 5em\"/></td>";
echo "<td>".(addVAT($price)*$count)."</td>";
echo "</tr>";
$total_price += addVAT($price)*$count;
}
$stmt->close();
$mysqli->close();
?>
When I look at the outputted HTML code it looks fine, I have pid[], count[] and price[] and all of them has the correct values. But when I post that form I get this:
Array
(
[oid] => 6
[pid] => 1
[count] => 1
[price] => Array
(
[0] => 570
[1] => 482
[2] => 455
)
)
Price is the only array, pid and count just contains the last value outputted on the previous page.
This has to be really simple, that is usually the case when I can't figure it out...