0

I want to insert all loop values into db my code written only the last value of my loop.How can I retrieve all loop values and inserted into database, help me to overcome this.And also I have to insert all values in single cell how can I do this.

<?php
$server="localhost";
$user="root";
$pswd="";
$dbname="desig";
$conn=mysql_connect($server,$user,$pswd);
mysql_select_db($dbname,$conn);

/*------Monthly-------*/

for($f=1;$f<=15;$f++)
{

    $factorname="wa".$f;
    if(!empty($_POST[$factorname]))
    {
        for($l=0;$l<$f;$l++)
       $factor=$_POST[$factorname];

       $labelname="fa".$l;
       $labmonth= $_POST[$labelname];
       $monthres=array();
       $impmonthres=array();
       $monthres[$l]=$labmonth.'-'.$factor;
       $t=0;
       $impmonthres[$t]=$monthres[$l].':';
       $t++;
     }  


}

    //$factorimp=array();
  // $factorimp=implode(',',$monthres);

 /*------Quaterlyweightage-------*/
 for($w=1;$w<=15;$w++)
 {
     $quaweight="we".$w;

     if(!empty($_POST[$quaweight]))
     {
        for($q=0;$q<$w;$q++)

         $quaweightvalue=$_POST[$quaweight];
         $qualabel="qa".$q;
         $qualabelname=$_POST[$qualabel];
         $quares=array();
         $quares[$q]=$qualabelname.'-'.$quaweightvalue;
         $quaresfin=array();
         $k=0;
         $quaresfin[$k]=$quares[$q].':';
         $k++;

     }

  }
  /*-------Annually-------*/

  $annualyvalue=$_POST['annualy'];
  if(!empty($_POST['annualy']))
  {
  $annualyres='A1'.'-'.$annualyvalue;
  }
  echo $annualyres;
  foreach($impmonthres as $monthvalue)
    {
      echo $monthvalue;
    }
    foreach($quaresfin as $Quaterlyvalue)
    {
        echo $Quaterlyvalue;
    }   
  $month=mysql_query("insert into workupdate(Empname,Designation,Monthly,Quaterly,Annualy)values('user','juniordeveloper','$monthvalue','$Quaterlyvalue','$annualyres') ",$conn);

?>
arjun
  • 57
  • 6

1 Answers1

0

You should check this thread:

insert multiple rows via a php array into mysql

But please upgrade your code, do you have many bad practices, in the future this going to give you a lot of issues

Community
  • 1
  • 1
aasanchez
  • 179
  • 1
  • 16