I'm trying to set up a panel that allows my admins to add posts. Not just one post, but multiple. They can click a button and it basically adds a few more input tags to add the name, link and description.
However, I'm having some issues with handling the $_POST[] values in PHP.
I'm doing something like so:
if(isset($_POST) === true){
$pNames = $_POST["postName"];
$pLinks = $_POST["postLink"];
$pDescs = $_POST["postDesc"];
foreach ($pNames as $pName) {
foreach($epLinks as $pLink){
foreach($pDescs as $pDesc){
// do stuff here
}
}
}
}
My issue is that, it's basically doing it for each possible value. (Which as expected, I guess)
What would be the best way to get all of these to match up and work the way I want it?
For example, if I added two posts it'd be something like:
PostName1, PostLink1, PostDescription1
Then PostName2, PostLink2, and PostDescription2
and I'd want them all to be grouped together so I can add them into mySQL database accordingly.
for ($i = 0; $i < count($_POST['posts']); $i++) { ... }and within the loop, use $i to reference each item i.e.$_POSTS['posts'][$i]['name'],$_POSTS['posts'][$i]['link'], etc. Using array notation for the form inputs will make this quite simple.