I have a form that allows the user to add more fields if they need them. When the user does this, two more fields appear (one for link text, the other for the link address). I'm use javascript to append a number onto the input names (e.g. newLinkTitle1
+ newLinkAddress1
, newLinkTitle2
+ newLinkAddress2
, etc.).
<input type="text" value="" name="newLinkTitle" size="50" />
<input type="text" value="http://" name="newLinkAddress" size="50" />
I want to check if there are variables in my POST array containing the prefix newLinkTitle
and then get the newLinkAdress
associated with it then add them to my database.
Currently I have this:
foreach ((strpos($_POST, 'newLinkTitle')) as $currentNewLinkTitle) { // check if newLinkTitle exists
$num = substr($currentNewLinkTitle, 12); // get the number following "newLinkTitle"
$currentLinkAddress = $_POST['newLinkAddress'.$num];
//Update query
}