Pass the value of the input to another page

1

I have a page where I get values from the database in a table.

        echo "<tr>";

        echo "<th>Empresa</th>";
        echo "<th>Categoria</th>";
        echo "<th>Serviço</th>";
        echo "<th>Descrição</th>";
        echo "<th>Pagamento</th>";
        echo "<th>Distrito</th>";
        echo "<th>Investimento</th>";



        echo "</tr>";

    $numLinhas = 0;
    while ($produto = mysql_fetch_array($produtos)) {
        $numLinhas++;

        echo "<tr class='table-hover'>";
        //echo "<td>".$produto['id']."-".$numLinhas."º</td>";
        echo "<td>autor:".$produto['user_of'] . "</td>";
        echo "<td>".$produto['id'] . "</td>";
        echo "<td>".$produto['categ'] . "</td>";
        echo "<td>".$produto['titulo'] . "</td>";
        echo "<td>".$produto['descricao'] . "</td>";
        echo "<td>".$produto['valor'] . "</td>";
        echo "<td>".$produto['local'] . "</td>";
        echo "<td>".$produto['investimento'] . "</td>";



        echo "<td><input style='width:40px' type='number' name='novo_investimento' value='0'><a href=up_invest.php?id=".$produto['id'].">
        <input name='submit' type='submit' value='Ok'></a></td> ";




        echo "</tr>";

    }
        echo "</table>";

In this same table I have an input number which I call 'new_investment'.

 echo "<td><input style='width:40px' type='number' name='novo_investimento'  value='0'><a href=up_invest.php?id=".$produto['id'].">
        <input name='submit' type='submit' value='Ok'></a></td> ";

In the up_invest.php page, where the data is processed, I would like to get the line id and the new value defined by the user from the 'new_investment' field of this line.

The way it is, on the up_invest.php page when I do this

 $id= $_REQUEST['id'];
 $investimento=$_REQUEST['novo_investimento'];
 echo "$id $investimento";

It just takes the id. How do I get the value of the field 'new_investment'?

Notice: Undefined index: novo_investimento

With the < form >

    echo "<td><form action='up_invest.php' method='post'><input  style='width:40px' type='number' name='novo_investimento' value='0'>
        <input name='submit' type='submit' value='Ok'></form></td> ";

It takes the value of 'new_investment', but loses the id of the line. How do I get the id of the line where this form is presented?

Solved. I created a hidden field with the ID value of the line.

 echo "<td><form id='form1' name='form1' action='up_invest.php'  method='post'><input style='width:40px' type='number' name='novo_investimento'  value='0'>

        <input type='hidden' name='id' value=".$produto['id'].">

        <input name='submit' type='submit' value='Ok'></form></td> ";
    
asked by anonymous 13.09.2015 / 18:44

2 answers

1

When we send a form to PHP (for the server in general) what is passed are elements like input, textarea, select. PHP receives an associative array where the keys are the values of the name attribute and the values that are assigned to each key come from the value attribute.

So if there is no element of this type with name="id" in HTML then PHP will not receive anything. So we have to add something like

<input name='id' value="algumValor" />

If you want to save the value of this line / id that comes from PHP, and you do not want it to be visible, then you can use type="hidden" and assign $produto['id'] to value of input . Something like this:

echo "<input type='hidden' name='id' value=".$produto['id']." />";

In this way the element is invisible but the server receives this information in $_POST .

    
13.09.2015 / 20:14
1

I was having a similar problem I brought from the database, given by a submit_1 to a table and if it had 50% filled it would need to get the id and make another submit_2 on the same page. Already I ended up saving the id of the first submit_1 in an input hidden and when I was going to fill the rest of the table I used this input hidden to update with submit_2.

    
13.09.2015 / 19:52