Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get id from a post php

So, i want to get id from $_POST["id"] when i push a button in a table

<form action="dosomething.php" method="post">
<td> <?php echo $row["id"]; ?> </td>
<td> <button>Do something</button> </td>
</form>

is that even possible?

thanks for any answers and help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes it is.

You will need to set a hidden input somewhere inside your form tags, like :

<form action="dosomething.php" method="post">
<input type="hidden" name="id" value="<?= $row["id"]; ?>" />
<td> <?php echo $row["id"]; ?> </td>
<td> <button onclick="this.form.submit();">Do something</button> </td>
</form>

This is not an elegant code and you should probably consider using javascript, especially if you have a lot rows and buttons.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading