I have a code that populates data from a mysql table into an html table. I also have a text box and a button at the end of each row. I want to send all the variables in the row including the text in the textbox to update.php. Could not do that somehow. Here is the code I am trying. Please help. I can send it through GET method. But I want to use POST.
<?php
require 'config.php';
mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db($dbname) or die('Cannot select database');
$query = "SELECT * FROM cust_info;";
$result = mysql_query($query) or die(mysql_error());
echo "</br>";
echo "<table border='1'>
<tr>
<th>Pop Code</th>
<th>Open_Date</th>
<th>Maturity_Date</th>
<th>Amount</th>
<th>Balance</th>
<th>Collection Amount</th>
</tr>";
while($row1 = mysql_fetch_array($result))
{
echo "<div class=\"addform\"><form method='post' action=\"update.php?upd=".$row1['pop_code']."\">\n";
echo "<tr>";
echo "<td>" . $row1['pop_code'] . "</td>";
echo "<td>" . $row1['open_date'] . "</td>";
echo "<td>" . $row1['mat_date'] . "</td>";
echo "<td>" . $row1['depoamt'] . "</td>";
echo "<td>" . $row1['balance'] . "</td>";
echo "<td>" . " <input type=\"text\" name=\"amount\"/>\n" . "</td>";
echo "<td>" . " <input type=\"image\" src=\"images/update.png\" alt=\"Update Row\" class=\"update\" title=\"Update Row\">\n" . "</td>";
echo "</tr>";
echo "</form></div>";
}
echo "</table>";
?>
Change your table code to something like this:
It looks like your code isn’t actually sending anything, just displaying it on the page. This will display it as well as sending a hidden field when the form is submitted.
Edit: Another way to do it would be to have a single form on your page outside your loop and have the button run a javascript function that copies the data to the form and submits the form. Probably easier the way you have it at the moment, but a javascript like that would be able to pick up other information off the user/page easily and send it via a single form to the next page.