Jump to content

How to use $_POST with the post name being a variable?


dink87522

Recommended Posts

$amountBoxName = "amount".$id; // Constructs the name of the input field
$amountToPay = strip_tags($_POST["$amountBoxName"]);

 

$amountBoxName then goes to 'amount22' says, however $amountToPay is then showing also as 'amount22', not getting the value of the text field whose name/id is amount22 on the previous page. How do I do this? I tried having " around the $amountBoxName, ' and no quotes although still can't get it working.

$amountToPay is then showing also as 'amount22'

 

Than that is what is in $_POST['amount22'] or you have some other code you are not showing that is setting $amountToPay to 'amount22' directly.

 

Have you used print_r() on the $_POST array so that you know what you are getting -

echo '<pre>',print_r($_POST,true),'</pre>';

long day, crazy ideas floating in head, here is one of them (TOTALLY untested - probably TOTALLY un-thought through...

name="amount[<?PHP echo $id; ?>]" /* this is for naming the form field */

$amountToPay = $_POST['amount[$id]']; /* this is for getting the form field value */

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.