Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing table data with post variables

Tags:

php

Basically I have a table with a bunch of numbers coming from a database with columns for totals/subtotals. I do not intend to add any of the totals to the database, but I need to pass the total numbers from one page to the next. I can't seem to properly pass them as post variables using PHP... I'm wondering if this is a bad tactic firstly, secondly what should I do instead?

And if this is possible, how would I go about doing it? I haven't been able to derive the text between the < td >'s from using $_POST['tdname'].

Example code:

<form method="POST" action="newcivilreport2.php">

            <div style="width:800px;text-align:left;margin:0 auto;padding-bottom:5px;">A. PENDING BALANCE</div>
            <table border="1" style="width:800px;" ID="tableA">
            <th style="width:40%;"></th>
            <th style="width:15%;">Civil</th>
            <th style="width:15%;">Asbestos</th>
            <th style="width:15%;">Domestic</th>
            <th style="width:15%;">Total</th>
            <tr>
            <td>1. Pending Balance from Previous Month</td>
            <td id="PendingCivil" name="PendingCivil">66</td>
            <td id="PendingAsbestos">0</td>
            <td id="PendingDomestic">0</td>
            <td id="PendingTotal">0</td>
            </tr>
            </table> 
<input type="submit" value="Save and Continue -->"></form></div>

newcivilreport2.php:

<?php
    $_POST['PendingCivil'];
?>
like image 853
Jeff Avatar asked Sep 12 '26 12:09

Jeff


1 Answers

POST will only send inputs like <input type='text|file|hidden|ect' />. Perhaps you would like to use AJAX. For example:

<table id="tData">
     <tbody>
         <tr>
             <td class='dataVal1'>100</td>
      ...

$(document).ready(function() {
    var toServer = {};
    var data = $('#tData tbody tr td').each(function(key, value) {
        toServer[$(this).attr('id')] = $(this).text();
    });
    $.ajax({
        url: 'page.php',
        data: toServer,
        type: 'POST'
    })
});
like image 88
Joe Avatar answered Sep 15 '26 01:09

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!