0

Project: Creating an invoice.

Problem is that when hitting submit, the rows in the table are populated, but if I need to insert another object in table, it will overwrite.

How can I do it to be inserted one after another instead?

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Printeaza</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
<div class="container">
<br>
    <div class="row">
        <div class="col-sm-6" style="background-color:black;">
            <form style="color:white;" method="post" action="dashboard.php" >
                <div class="form-group">
                    <label for="nrcrt">Nr Crt:</label>
                    <input type="text" class="form-control" id="nrcrt" name="nrcrt" >
                </div>
                <div class="form-group">
                    <label for="denumireproduse">Denumire produse:</label>
                    <input type="text" class="form-control" id="denumireproduse" name="denumireproduse" >
                </div>
                <div class="form-group">
                    <label for="um">UM:</label>
                    <input type="text" class="form-control" id="um" name="um" >
                </div>
                <div class="form-group">
                    <label for="cantitate">Cantitate:</label>
                    <input type="text" class="form-control" id="cantitate" name="cantitate" >
                </div>
                <div class="form-group">
                    <label for="pretunitar">Pret Unitar(fara tva):</label>
                    <input type="text" class="form-control" id="pretunitar" name="pretunitar">

                </div>

                <input type="submit" class="btn btn-default">
                <p></p>

            </form>
        </div>






        <?php
            if(isset($_POST['nrcrt']) && isset($_POST['denumireproduse']) && isset($_POST['um']) && isset($_POST['cantitate']) && isset($_POST['pretunitar']))
            {
                $nrcrt = $_POST['nrcrt'];
                $denumireproduse = $_POST['denumireproduse'];
                $um = $_POST['um'];
                $cantitate = $_POST['cantitate'];
                $pretunitar = $_POST['pretunitar'];
                $valoarefaratva = $pretunitar * $cantitate;
                $valoaretva = ($valoarefaratva / 100) * 19;
                $valoaretotala = $valoarefaratva + $valoaretva;

            }
            else
            {
                $nrcrt = 0;
                $denumireproduse = 0;
                $um = 0;
                $cantitate = 0;
                $pretunitar = 0;
                $valoarefaratva = 0;
                $valoaretva = 0;
                $valoaretotala = 0;

            }

        ?>


        <div class="col-sm-6" style="background-color:green;">

            <table class="table table-striped" id="tabel">
                <thead>
                    <tr>
                        <th>Nr. Crt.</th>
                        <th>Denumire Produse</th>
                        <th>UM</th>
                        <th>Cantitate</th>
                        <th>Pret Unitar (fara TVA)</th>
                        <th>Valoare (fara TVA)</th>
                        <th>Cota TVA</th>
                        <th>Valoare TVA</th>
                        <th>Valoare Totala</th>
                    </tr>
                </thead>

                <tbody>
                    <tr> 
                        <td> <?php echo $nrcrt; ?> </td>
                        <td> <?php echo $denumireproduse; ?> </td>
                        <td> <?php echo $um; ?> </td>
                        <td> <?php echo $cantitate; ?> </td>
                        <td> <?php echo $pretunitar; ?> </td>
                        <td> <?php echo $valoarefaratva; ?> </td>
                        <td> <?php echo 19; ?> </td>
                        <td> <?php echo $valoaretva; ?> </td>
                        <td> <?php echo $valoaretotala; ?> </td>
                    </tr>
                </tbody>
            </table>    



        </div>

    </div>

</div>

</body>
</html>
chrki
  • 6,143
  • 6
  • 35
  • 55
  • 1
    Your script is vulnerable to a remote code injection attack ... Also duplicate question.. http://stackoverflow.com/questions/18333427/how-to-insert-row-in-html-table-body-in-javascript – mike510a Jan 05 '17 at 12:26
  • very useful information. thanks mike510a – Catalin Jan 05 '17 at 23:24

0 Answers0