1
I have a page where I receive in a table values from the database.
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> ";
On the up_invest.php page, where the data is processed, I would like to take the line id and the new value defined by the user of 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";
He just picks up the id. How do I get the value of the 'new investment' field'?
Notice: Undefined index: novo_investimento
With the < form element >
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 line id. How do I get the line id where this form is displayed?
Solved. I created an Hidden field with the line ID value.
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> ";
Seems right to me. You can put the HTML that reaches the page to be clearer as the HTML?
– Sergio
On the page where I handle the data, I don’t have html yet, I just wanted to get the values. On the page where the data are presented the first time is only one table, where they appear in their own <td>. I’m not getting the 'new investment' value. I don’t know why...
– David Concha
Put this HTML, even simple, in the question or in a jsFiddle to see if we find the problem... For example in this PHP I do not see the element
<form>
– Sergio
I was with a similar problem I brought from the database by a submit_1 to a table and if it had 50% filled would need to take the id and make another submit_2 on the same page so I ended up saving the id of the first Ubmit in a Hidden input and when to fill the The rest of the table used this Hidden input to update with submit_2. Summary when bringing the data from the database save what you want in Hidden inputs (already inside form_2) to use later with submit_2.
– Thalles Daniel
That’s what I ended up doing. I created an Hidden input with the ID line value and passed it :)
– David Concha
I’ll put as an answer to help the other blz :)
– Thalles Daniel