I have a form that will send data via POST. I want that data to go to different MySQL tables based on the POST “name.”
What I have so far is a while loop for the form fields that will name each input in the format: “name”{}$id. I thought that using {} as a delimiter I could then use explode() and use a conditional statement to select which table the data should go to.
Is this the best way to do this? The issue I’m having is also calling the name, since using foreach for example on POST will just return the values and not the names. I have enclosed the code below:
<?php while ($cred = mysql_fetch_array($credentials_process)) { ?>
<div class="edit-profile-background-inputs">
<span><input type="text" name="cred{}<?php echo $cred['id']; ?>" value="<?php echo $cred['credentials']; ?>" /></span>
<span style="margin-left:10px;"><a href="<?php echo "background.php?cred=".$cred['id']; ?>">Remove</a></span>
</div>
<?php } ?>
I need those fields named cred{} to go to credentials table, those named edu{} to go to the education table, etc.
in PHP
repeat for
$_POST['edu']If your results set is such that you’re outputting more than one row with the same key
If you
print_r($_POST)from that you’ll be able to figure out how to deal with them.NB. For safety I would also make sure only the expected posted vars get used