Reputation: 65
I'm trying to update the table in DB and every row (result) has its own update button which is a form. When i click the button nothing happens because I don't know how to transfer value of id to a form and then to a UPDATE query.
while(list($naziv,$tvrtka_id)=mysqli_fetch_row($resultA))
{
echo "<tr>";
echo "<td>".$naziv."</td>";
echo "<td>"?>
<form action="" method="POST">
<input type="hidden" name="id" value="<?php $tvrtka_id; ?>">
<input type="submit" name="odobriZahtjev" value="Odobri zahtjev">
</form> <?php "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
} //this is from a if statment which creates table
if(isset($_POST['odobriZahtjev']))
{
$firmId = $_POST['id'];
$updateAnswers = "UPDATE tvrtka
SET zahtjev = '0', preostaliOdgovori=preostaliOdgovori + 10
WHERE tvrtka.tvrtka_id='$firmId'";
$result=queryDB($connect,$updateAnswers);
}
When button is clicked the value of a request for answers is set to 0 and 10 answers are added to company. tvrtka_id is the id which is supposed to go to a UPDATE query.
Upvotes: 0
Views: 168
Reputation: 4483
When using a PHP var inside HTML you have to print it to the HTML (using echo
in your case).
<input type="hidden" name="id" value="<?php echo $tvrtka_id; ?>">
This will probably solve the problem with your update query when the form is submitted too
Upvotes: 1