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);	
  }			
}

4
  • how is that data generated? That is a very unusual structure Commented Oct 23, 2019 at 7:14
  • You should look into using prepared statements, but you seem to be using some library for your SQL so not sure how this would be supported. Commented Oct 23, 2019 at 7:15
  • @RamRaider im using Kendo Ui grid form. And one of the grid column can be select more than one value. When submit it sent those structure Commented Oct 23, 2019 at 7:19
  • "Sometimes" looks strange. What have you tried to debug the problem? Commented Oct 23, 2019 at 7:35

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

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!? )

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.