2015-09-01 63 views
0

我正在使用yii2,我需要將編輯值插入數據庫並編輯 列由ajax創建。在PHP列中插入 properly..thanks提前顯示未定義的索引..編輯值未插入到數據庫中

if(isset($hotelInsertId)){ 
      $noOfSeason = $_POST['numOfSeason']; 
    $seasonRow = 1; 


      for($i=0;$i<$noOfSeason;$i++){ // strt season loop 


       $from_date_season = $_POST['season_from_date'.($seasonRow-1)]; 
       $to_date_season = $_POST['season_to_date'.($seasonRow-1)]; 

       $from_date = date('m/d/Y',strtotime($from_date_season)); 
       $to_date = date('m/d/Y',strtotime($to_date_season)); 


       $year1= date('Y',strtotime($from_date_season)); 
       $year2= date('Y',strtotime($to_date_season)); 

       $day = date('d',strtotime($from_date_season)); 
       $month = date('m',strtotime($from_date_season)); 

       $from_date_unix = strtotime($from_date); 
       $to_date_unix = strtotime($to_date); 

       $datediff =$to_date_unix - $from_date_unix; 
       //echo $datediff; 

       $no_of_days = floor($datediff/86400); 

       //$seasonIds=$seasonArray[$seasonRow-1]; 
       $seasonIds = 0; 

       if(($i+1)%$roomCatNo!=0){ 
        $seasonRow++; 
       } 
       else{ 
        $seasonRow++; 
       } 


       $from_date_a = explode('-',$from_date); 

       $to_date_a  = explode('-',$to_date); 

       if($from_date_unix < $to_date_unix) { 

        if($to_date_a[0] >= $from_date_a[0]) { 

         for($j=0;$j<$roomCatNo;$j++){ 

          if(((0 == $year1 % 4) and (0 != $year1 % 100) or (0 == $year1% 400))||((0 == $year2 % 4) and (0 != $year2 % 100) or (0 == $year2 % 400))) { 
           $no_of_days_leap = $no_of_days + 2; 

          } 
          else{ 
           $no_of_days_leap = $no_of_days + 1; 

          } 



          for ($k=0;$k<$no_of_days_leap;$k++) { 


          $roomType1  = $_POST['int_no_of_room'.$i.$j]; 

          $roomNo1  = $_POST['int_roomNo'.$i.$j]; 
          $personNo1  = $_POST['int_personRoom'.$i.$j]; 
          /*$rakRatePkg1 = $_POST['float_rackRatePackage'.$i.$j];*/ 
          $spRatePkg1  = $_POST['float_specialRatePackage'.$i.$j]; 
          $rkRateHtl1  = $_POST['float_rackRateHotel'.$i.$j]; 
          $spcRatehtl1 = $_POST['float_specialRateHotel'.$i.$j]; 

          $modelHotelRateId = $_POST['int_rateId'.$i]; 
          $modelHotelRate = new \common\models\TblHotelRate; 
          $modelHotelRate->isNewRecord = true; 
          //$modelHotelRate->primaryKey = NULL; 
          $modelHotelRate->int_hotelId = $hotelInsertId; 
          $modelHotelRate->season_from_date = $from_date_unix; 
          $modelHotelRate->season_to_date = $to_date_unix; 
           $modelHotelRate->season_days = strtotime($from_date. ' + ' .$k. 'day'); 

           $modelHotelRate->int_season_id = $noOfSeason; 
          //$modelHotelRate->s_fd_md = $s_fd_md; 
          //$modelHotelRate->s_td_md = $s_td_md; 
          $modelHotelRate->no_of_days = $no_of_days; 
          $modelHotelRate->int_roomCatId = $roomType1; 
          $modelHotelRate->int_roomNo = $roomNo1; 
          $modelHotelRate->int_personRoom = $personNo1; 
          /*$modelHotelRate->float_rackRatePackage = $rakRatePkg1;*/ 
          $modelHotelRate->float_specialRatePackage = $spRatePkg1; 
          $modelHotelRate->float_rackRateHotel = $rkRateHtl1; 
          $modelHotelRate->float_specialRateHotel = $spcRatehtl1; 
          $modelHotelRate->save(false); 
          } 

         } 
        } 

       } 


      } 

     } 

「未定義指數:int_no_of_room20」 價值觀爲錯誤....我得到後值 正確....

回答

0

使用此

if(isset($_POST['int_no_of_room'.$i.$j])) 
    $roomType1  = $_POST['int_no_of_room'.$i.$j]; 
else 
    $roomType1 = "Not set !" 
+0

解決了這個問題.... – MaRKR