-2

I try to get value by using odbc_fetch_array and turn them into variable but when i try to echo it's just said "arrayarrayarray"

Array ( 
  [0] => Array ( [PKDSEQ] => 154604 ) 
  [1] => Array ( [PKDSEQ] => 154604 ) 
  [2] => Array ( [PKDSEQ] => 154529 ) 
  [3] => Array ( [PKDSEQ] => 161689 ) 
  [4] => Array ( [PKDSEQ] => 158940 ) 
  [5] => Array ( [PKDSEQ] => 155383 ) 
  [6] => Array ( [PKDSEQ] => 156247 ) 
  [7] => Array ( [PKDSEQ] => 158123 ) 
)

and is there a way to get array separate into number?

Code

  $PKDSEQ2 = array();
  $table4 = "SELECT [PKDSEQ] FROM [PWSWMS].[dbo].[tbTR_PACKD] WHERE [PKDSEQ] = '$PKDSEQRS5'";
  $RS4 = odbc_exec($connection2, $table4);

  while ($PKDSEQ2 = odbc_fetch_array($RS4)) {
    $PKDSEQ[] = $PKDSEQ2;
  }
}

print_r(array_values($PKDSEQ));

if(isset($_POST['QTYINPUT1'])) {
  $QTYINPUT1 = $_POST['QTYINPUT1'];
  $update = "UPDATE [PWSWMS].[dbo].[tbTR_PACKD] SET QTYPCK='$QTYINPUT1' WHERE [PKDSEQ]='$PKDSEQ[1]'";
  $result = odbc_exec($connection2, $update);
  echo "<br>$QTYINPUT1";
  echo "<br>$PKDSEQ[1]";
}
ADyson
  • 57,178
  • 14
  • 51
  • 63
Tachin
  • 3
  • 3
  • 2
    Your code is vulnerable to SQL injection attacks. Your should use parameterised queries and prepared statements to help prevent attackers from compromising your database by using malicious input values. http://bobby-tables.com gives an explanation of the risks. See https://stackoverflow.com/questions/5756369/odbc-prepared-statements-in-php for examples of how to use prepared statements with ODBC in PHP. – ADyson Dec 17 '21 at 10:09

1 Answers1

0

You've got an associative array within each entry in $PKDSEQ. So you need to refer to the property of that array which you want to output. Since the array happens to only have one property, it's pretty simple to choose:

echo "<br>".$PKDSEQ[1]["PKDSEQ"];
ADyson
  • 57,178
  • 14
  • 51
  • 63