0

I had this data (refer 2nd image below) and php function that fetch those data's then insert into the database. Somehow the function not manage to insert $outletID, it manage to loop 3 times and data insert into it, but at column outletID it insert Array as a value. Any idea what Im doing wrong here?

ra

enter image description here

function addRevenueAccounts(){
  global $Obj;  
  $recipeTypeID = (isset($_POST['recipeTypeID']) ? $_POST['recipeTypeID'] : '');
  $outletID     = (isset($_POST['outletID']) ? $_POST['outletID'] : ''); 
  $accountID    = (isset($_POST['accountID']) ? $_POST['accountID'] : '');

  $countOutletID = sizeof($outletID);
  for($x=0; $x< $countOutletID; $x++ ){

    $revenueAccountID = $Obj->GENERATE_PK("tblAccRevenueAccounts");
    $sqlAdd = "INSERT INTO tblAccRevenueAccounts
              SET revenueAccountID = '".$revenueAccountID."',
              outletID = '".$outletID[$x]."',
              accountID = '".$accountID."',
              recipeTypeID = '".$recipeTypeID."',
              dateTimeEmployee = NOW(),
              active = 'y' ";
    $Obj->ExecuteData($sqlAdd, $Obj->DEFAULT_PDO_CONNECTIONS); 
  }   
}

2 Answers2

1

You need to use $outletID[$x]['OutletID'], otherways you'll get whole array (outletID, outletName, index, checked, ...)

Pavel Třupek
  • 898
  • 6
  • 19
1

Your structure is a bit weird, but your naming convention is weirder. Anyway updated code below (you where inserting the whole array into the database):

$sqlAdd = "INSERT INTO tblAccRevenueAccounts
          SET revenueAccountID = '".$revenueAccountID."',
          outletID = '".$outletID[$x]['outletID']."',
          accountID = '".$accountID."',
          recipeTypeID = '".$recipeTypeID."',
          dateTimeEmployee = NOW(),
          active = 'y' ";

PS: Posted from phone, no code formatting available! ( why!? )

Mecanik
  • 1,539
  • 1
  • 20
  • 50