1

I have a single HTML form that allows users to insert or update multiple rows in a database with a single submission. However, I don't know what the "correct" or industry standard way to match input names against certain rows is.

The way I have implemented it currently is to give each a human-readable name, followed by a delimiter (in my case an underscore _ character), followed by the row number or some other unique identifier to tie the several inputs together against one row. Then, in the processing script, I do $field = explode("_",$name) against each name, using $field[0] to get the name and $field[1] to get the unique ID.

However, in my past programming experience I have attempted to keep multiple sets of data like this discrete, instead of tying them together in a single string. I also now know that PHP accepts form names formatted as arrays and converts them into arrays automatically.

What is the industry standard method of handling this situation?

1
  • You lat assumption is right. You want something like id="name []" in each input Commented Mar 5, 2014 at 10:33

1 Answer 1

1

HTML

<form method="POST">
    <input type="text" name="myinput[]" value="some value"/><br/>
    <input type="text" name="myinput[]" value="second value"/><br/>
    <input type="text" name="myinput[]" value="another value"/><br/>
    <input type="submit"/>
</form>

PHP

<?
foreach ($_POST["myinput"] as $value) {
    echo "myinput : " . $value . "<br/>";
}
?>
Sign up to request clarification or add additional context in comments.

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.