I have multiple textbox with same name, example :
<input type = "text" name = "addCart"/>
<input type = "text" name = "addCart"/>
<input type = "text" name = "addCart"/>
<input type = "text" name = "addCart"/>
If I do a $_Request from php and I want to get the value inputted only from the first and fourth textbox, how can I do it? Thanks
You can’t. The last input box’s value will overwrite all of the other ones’ since they have the same name.
What you could consider doing is using
name="addCart[]"Then, $_REQUEST[‘addCart’] would be an array.
Like:
Then $_REQUEST[‘addCart’] (or $_POST or $_GET whichever you’re using) would contain an array of two strings ‘a’ and ‘b’.
Edit: Just for completeness, I should note that this array is a normal array. Thus $_REQUEST[‘addCart’][x] where x is some integer index is valid as long as count($_REQUEST[‘addCart’]) > x.