Dynamic rows problems

Sir,
when i submit my dynamic rows ( suppose add 3 rows) values then "sub_brand_name " save correctly and other fields save same values 3 times.
where is my problems?

here is my code:

<?php

if (isset($_POST['title']) && sizeof($_POST['title']) > 0) {
    $title = array_map('trim', $_POST['title']);
    foreach($title as $title) {
}
if (isset($_POST['start_time']) && sizeof($_POST['start_time']) > 0) {
    $start_time = array_map('trim', $_POST['start_time']);
    foreach($start_time as $start_time) {
    }
if (isset($_POST['end_time']) && sizeof($_POST['end_time']) > 0) {
    $end_time = array_map('trim', $_POST['end_time']);
    foreach($end_time as $end_time) {
  }
if (isset($_POST['peak_offpeak']) && sizeof($_POST['peak_offpeak']) > 0) {
    $peak_offpeak = array_map('trim', $_POST['peak_offpeak']);
    foreach($peak_offpeak as $peak_offpeak) {
  }
if (isset($_POST['program_name']) && sizeof($_POST['program_name']) > 0) {
    $program_name = array_map('trim', $_POST['program_name']);
    foreach($program_name as $program_name) {
  }
if (isset($_POST['product_name']) && sizeof($_POST['product_name']) > 0) {
    $product_name = array_map('trim', $_POST['product_name']);
    foreach($product_name as $product_name) {
  }
if (isset($_POST['sponsor']) && sizeof($_POST['sponsor']) > 0) {
    $sponsor = array_map('trim', $_POST['sponsor']);
    foreach($sponsor as $sponsor) {
  }
if (isset($_POST['sub_brand_name']) && sizeof($_POST['sub_brand_name']) > 0) {
    $sub_brand_name = array_map('trim', $_POST['sub_brand_name']);
    foreach($sub_brand_name as $sub_brand_name) {
   



 mysql_query("INSERT INTO entry_history (date,channel_name,title,start_time,end_time,peak_offpeak,product_name,program_name,sponsor,sub_brand_name) VALUES ('$date','$channel_name','$title','$start_time','$end_time','$peak_offpeak','$product_name','$program_name','$sponsor','$sub_brand_name')");
       }
       }
       }
       }
       }
       }
       }
       }   
       }
 else {
    exit('No values entered');
}
header('location:entry_history.php');

?>

Each of your “if” statements are being closed at the end of the script, but it looks like your foreach loops are all being closed without anything happening inside them. There is something wrong with your nesting.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.