1

I've setup a form with a table which includes rows from a database. I've used a variable to represent the database record ID as the name for one of the rows like this:

<td><input type="text" name= "<?php echo $recordID; ?>" class="form-control" placeholder="User Notes"></td>

which is working fine and ends up appearing like this in the browser:

<td><input type="text" name= "TSL1406" class="form-control" placeholder="User Notes"></td>

I'm having trouble retrieving the value when the form is submitted. I would normally use something like this:

$input = $_POST['userNotes']

which I've updated to handle the dynamic naming of the inputs like this:

$input = $_POST['.$recordID.'];

but this is returning an empty variable and I can't work out the correct syntax to retrieve the input from the $_POST array with a dynamically named input field?

1

3 Answers 3

1

single quote " ' " means literal, it won't display your variable name just literally .$recordID.. Try using double quotation instead.

$input = $_POST[".$recordID."];
Sign up to request clarification or add additional context in comments.

1 Comment

That didn't work but this did: $input = $_POST["$recordID"]; - i.e. remove the period between the double quote and the variable name
1

Only $input = $_POST[$recordID]; without quotes?

or you use arrays like:

<input type="text" name= "form[<?php echo $recordID; ?>]" class="form-control" placeholder="User Notes"></td>

and save everything at once

$input = $_POST['form'];

Comments

0

Why don't you just simply use $_POST[$recordID]? However there is a better way to get POST variable using filter_input(INPUT_POST, $recordID)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.