hello i have the following javascript which populates my fields and works fine
<script type="text/javascript">
var count = 0;
$(function(){
$('p#add_field2').click(function(){
count += 1;
$('#container').append(
'<strong>Link #' + count + '</strong><br />'
+ '<input id="field_' + count + '" name="fields[]' + '" type="text" /><input id="field1_' + count + '" name="idrima' + '" type="text" /><input id="field2_' + count + '" name="code_title' + '" type="text" /><input id="field3_' + count + '" name="name_title' + '" type="text" /><input id="field4_' + count + '" name="vathmos_title_a' + '" type="text" /><input id="field5_' + count + '" name="vathmos_title_d' + '" type="text" /><input id="field6_' + count + '" name="etos' + '" type="text" /><br />');
});
});
</script>
my problem is that when i use foreach i m able to add just the last field poppulation and not all. So i think foreach doesnt work cause adds only the last record. My code is
if ($_POST['fields']) {
//get last inserted userid
$inserted_user_id = $db->last_insert_id();
//Loop through added fields
foreach ( $_POST['fields'] as $key=>$value ) {
//Insert into websites table
$sql_website = sprintf("INSERT INTO spoudes (idrima,code_title) VALUES ('%s','%s')",
mysql_real_escape_string($_POST['idrima']),
mysql_real_escape_string($_POST['code_title']));
$result_website = $db->query($sql_website);
$inserted_website_id = $db->last_insert_id();
//Insert into users_websites_link table
$sql_users_website = sprintf("INSERT INTO spoudes_link (id_fakelos, id_spoudes) VALUES ('%s','%s')",
mysql_real_escape_string($inserted_user_id),
mysql_real_escape_string($inserted_website_id) );
$result_users_website = $db->query($sql_users_website);
}