have two JavaScript functions which will add or delete lines. I didn't include
the JavaScript here but I can if it is needed to resolve my issue. Now I want
to be able to make changes to the lines items and save them back to the
database. This is where my trouble begins. I can't figure out how get each of
the values from $_POST so I can process them and update my database table.
Code: Select all
$titles = array('invlineid','invoiceid','quantity','unitprice','itemdesc');
$headers = array('invlineid','invoiceid','quantity','unitprice','itemdesc');
$sql = "SELECT ";
foreach(array_combine($headers, $titles) as $header => $title)
{
$sql .= "$header as $title,";
}
$sql .= "linetotal as linetotal";
$sql .= " FROM invoicelineitem";
$sql .= " WHERE invoiceid = 1096";
try
{
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error getting invoice line items.---' . $e . '----' . $sql;
include $_SERVER['DOCUMENT_ROOT'] . '/mincludes/error.html.php';
exit();
}
if ($result !== false)
{
$html_table = '<table>';
$html_table .= '<thead><tr>';
foreach($titles as $title)
{
$html_table .= "<th> $title </th>";
}
$html_table .= '</tr> </thead>';
$html_table .= '<tbody id="dataTable">';
foreach($result->fetchAll(PDO::FETCH_ASSOC) as $row)
{
$html_table .= '<tr>' . "\n";
foreach($row as $col)
{
$html_table .= '<td>';
$html_table .= '<input type=text name=' . $title;
$html_table .= ' value=' . $col . '>';
$html_table .= '</td>' . "\n";
}
$html_table .= '</tr>' . "\n";
}
}
$html_table .= '</tbody> <tr> </table>';