What im doing is i have a form with 4 inputs like below. and im using the post method to store the fields values so i can send them to the database. what i neeed is each input to be put into a separate row in a databases table.
also sometimes maybe only 3 of the 4 fields are filled and therefore i would like only three new rows in my table.
Ive managed to get this going but it will always add 4 rows even if some of the input fields were blank.
so idk i think i need an array like idk $links = array();
foreach ( $_POST as $key => $value)
but im not sure how to achieve this. could someone help.
<table width="100%">
<tr>
<td width="140" style="padding:4px;">link 1:</td>
<td ><input type="text" class="edit bk" name="link_one" style="width:350px"></td>
</tr>
<tr>
<td width="140" style="padding:4px;">link 2:</td>
<td ><input type="text" class="edit bk" name="link_two" style="width:350px"></td>
</tr>
<tr>
<td width="140" style="padding:4px;">link 3:</td>
<td ><input type="text" class="edit bk" name="link_three" style="width:350px"></td>
</tr>
<tr>
<td width="140" style="padding:4px;">link 4:</td>
<td ><input type="text" class="edit bk" name="link_four" style="width:350px"></td>
</tr>
<tr>
</tr>
</table>
<?php
$link_one = trim( $db->safesql( $parse->process( $_POST['link_one'] ) ) );
$link_two = trim( $db->safesql( $parse->process( $_POST['link_two'] ) ) );
$link_three = trim( $db->safesql( $parse->process( $_POST['link_three'] ) ) );
$link_four = trim( $db->safesql( $parse->process( $_POST['link_four'] ) ) );
$db->query( "INSERT INTO " . PREFIX . "_post_links (matchid, link) VALUES('{$row}', '{$link_one}')" );
$db->query( "INSERT INTO " . PREFIX . "_post_links (matchid, link) VALUES('{$row}', '{$link_two}')" );
$db->query( "INSERT INTO " . PREFIX . "_post_links (matchid, link) VALUES('{$row}', '{$link_three}')" );
$db->query( "INSERT INTO " . PREFIX . "_post_links (matchid, link) VALUES('{$row}', '{$link_three}')" );
?>
I need to make this an array so it doesnt add rows when its not needed. also to make it less redundant.
any help please and thanks.