Ι'm new in PHP and I have a problem in getting data from POST.
I have an SQL query which selects from a table 3 columns, which I echo in a table form.
Notice that only the 3rd column should be input type.
Although the table is displayed fine (all values from mySQL),
when I print the 3rd column variable from $_POST
, only the last value is printed.
Here is the code:
$result = mysql_query("SELECT `id`, `component`,`percentage` FROM `waste_percentage` ")or die(mysql_error());
$row = mysql_fetch_array($result);
echo "<table border='1' cellspacing='0'>
<tr>
<th>α/α</th>
<th>Ρεύμα</th>
<th>Ποσοστό</th>
</tr>";
while($row = mysql_fetch_array($result))
{
$num = mysql_numrows($result);
$i=0;
while ($i < $num)
{
$field1 = $i +1;
$field2=mysql_result($result,$i,"component");
$field3=mysql_result($result,$i,"percentage");
$i++;
echo "<form action=\"\" method=\"post\">";
echo "<tr>";
echo "<td> $field1 </td>";
echo "<td> $field2 </td>";
echo "<td>" . "<input type=\"text\" name=\"percentage\" value=" . $field3 . " </td>";
echo "<td>" . "<input type=\"hidden\" name=\"hidden\" value=" . $row['id'] . " </td>";
echo "</tr>";
}
}
echo "</table>";
echo "<input name=\"Submitpercent\" type=\"submit\" value=\"Συνέχεια\" />";
echo "</form>";
//When I try to output
if(isset($_POST['Submitpercent']))
{
$user_percentage [] = $_POST['percentage'];
print_r ($user_percentage);
}
Output is: 'Array ( [0] => 13.60 )'. I would appreciate any help! Thanks in advance.