0

hello guys i am trying to put an array in $_SESSION[] variable, but when i try to run the code it triggers this:

Notice: Undefined offset: 1

here is my code

$stmt1=$conn->prepare('SELECT st_id FROM stores WHERE user_id= :user_id');
 $stmt1->bindParam(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
$stmt1->execute();
$numofst=$stmt1->fetchAll(PDO::FETCH_ASSOC);
foreach ($numofst as $row){
$_SESSION['st_id']= $row;
}
echo $_SESSION['st_id'][1];

i tried to change the position of the number that points the column for example echo $_SESSION[1]['st_id']; but i get the same error

when i put the rows in normal array for example :

 $stmt1=$conn->prepare('SELECT st_id FROM stores WHERE user_id= :user_id');
  $stmt1->bindParam(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
  $stmt1->execute();
$numofst=$stmt1->fetchAll(PDO::FETCH_ASSOC);
foreach ($numofst as $row){
$stores_number[]= $row;
}
echo $stores_number[1]['st_id'];

everything works fine with no issues

what am i missing guys?

thanks in advance

vaggelis

vaggelis
  • 60
  • 2
  • 9

0 Answers0