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.

Link to comment
Share on other sites

$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>';

Link to comment
Share on other sites

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 */

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.