I am having a looped form in my site, but i have a problem on saving it.
I don't know where is my mistake. Please someone help me.

i have 5 records. in my code it saves only one record. and its not giving the correct value. it shows "Array" only.


Here's my Code:

<?php 
if (!$_POST)   
    { ?>
            <fieldset>
        <form id="formID" class="formular" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" style="width:1200px">
               
        <table border=1>
<?PHP
            $sql="SELECT * FROM records WHERE is_active = 'Yes'";   
            $result=mysql_query($sql,$connection) or die(mysql_error());
            
 $count=1;
 
        while ($row=mysql_fetch_array($result)) {
                $id = $row["id"];
                $name = $row["name"];
                $labour_id = $row["labour_id"]; 
                $bank_id = $row["bank_id"];
                $iban_no = $row["iban_no"];
                $default_salary = $row["default_salary"];
                $num_rows = mysql_num_rows($result);
             

        echo "<tr>";
        echo "<td>";
        echo $count."</td>";
        echo "<td>";
        echo "<input type=\"text\" id=\"name[$id]\" size=\"20\" name=\"name[$id]\" value=\"$name\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" class=\"validate[required,custom[onlyLetterNumber],maxSize[3],minSize[3]] text-input\" id=\"edr[$id]\" size=\"13\" name=\"edr[$id]\" value=\"EDR\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" class=\"validate[required,custom[onlyLetterNumber],maxSize[14],minSize[14]] text-input\" id=\"labour[$id]\" size=\"14\" name=\"labour[$id]\" value=\"$labour_id\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" size=\"8\" name=\"bank_id[$id]\" value=\"$bank_id\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" size=\"25\" name=\"iban_no[$id]\" value=\"$iban_no\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" size=\"8\" name=\"datestart[$id]\" value=\"2012-01-01\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" size=\"8\" name=\"dateend[$id]\" value=\"2012-01-31\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" size=\"1\" name=\"numofdays[$id]\" value=\"31\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" size=\"4\" name=\"default_salary[$id]\" value=\"$default_salary\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" size=\"4\" name=\"additional_salary[$id]\" value=\"\">";
        echo "</td>";
        echo "<td width=\"\" align=\"left\" border=\"0\">";
        echo "<input type=\"text\" size=\"1\" name=\"absent[$id]\" value=\"\">";
        echo "</td>";
        echo "</tr>";

               $count++ ;
             } 
        echo "</table>"
  ?><br>
 
            </fieldset>

            
            
            <input class="submit" type="submit" value="Validate!"/><hr/>
            
        </form>
  <?php }
  else
  {
    echo "File has been validated and NO possible error found!";
    
$Employee_Name=$_POST['name[]']; //takes the data from a post operation...
   
$sql="insert into saved_records (Employee_Name) 
                values('$Employee_Name')";
$result=mysql_query($sql,$connection) or die(mysql_error());

 
  }      
       ?>

do something like

$NameArray=$_POST['name'];
foreach($NameArray as $Employee_Name)
   {

do something like

$NameArray=$_POST['name'];
foreach($NameArray as $Employee_Name)
   {

gotcha! thanks pzuurveen!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.