MySQL Forums
Forum List  »  PHP

POSTing a a value from inside a table, using hidden field and submitting using JavaScript
Posted by: Guest Guest
Date: October 29, 2018 06:25AM

My question is related to form handling after a set of rows are retrieved from MySQL in PHP.

I can display rows in a table, and I need to jump to another PHP file when I click one of the columns.

When I use GET it is easy. For example, when I click a row at a cell showing 'title', I pass 'recID' as a key for the <a href ...>, I just do the following:

<td>
<a href='showDetails.php?key=<?php echo $row['recID']?>'><?php echo $row['title']?></a>
</td>

But I am writing this message because I am trying to send the recID using POST and using <a href..>, not <input name="submit" type="submit" />.

I found several posts in Google suggesting I use a form with hidden value, and use JavaScript to submit.

I have created a sample, but whichever row I click, I get the same recID on my POST value. Each row has unique recID, and when I click different rows, I want to see a corresponding, different recID.

Here is a part of my code:

<td>

<form method="post" name="form1" action="showDetails.php">

<input type="hidden" name="recNo" value="<?php echo $row["recNo"]; ?>">

<a href="javascript: void(0)"
onclick="document.forms[0].submit(); return false;">...</a>
</form>

</td>

The ... has PHP echo for 'title'.

The form submits fine, and when I check
print_r($_POST);
in showDetails.php file, I only get the recID belonging to the first record, whichever row I click.

Please note that the rows are inside a table.

<table>

<?php
while ($row = $stmh->fetch(PDO::FETCH_ASSOC)) { ?>

<tr>
<td>
... my sample code goes here....
</td>
</tr>
<?php
}?>
</table>


Sorry for a long winded post and my apology if it is not the right forum.

Thank you.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.