I'm Facing problem in adding variable or row from database into $_SESSION
.
Here i'm fetch rows from database and storing it into $_SESSION with the help of array. But i'm not able to update/add/delete row quantity in $_SESSION[]
.
I will be very thankful if you tell me what is the proper way of adding arrays to $_SESSION[]
and how to update/delete its particular row only in $_SESSION[]
. When i use in_array()
it only finds the last row values. when i try to find values of 2nd or 3rd row it says not found.
Note : I have searched in stackoverflow for this question. but those answere not come close to my question. Here are those links below link1 ,link2, link3
Here is my database table :
my Output :
PHP page :
<?php
$link = new mysqli('localhost','root','admin','pavancart');
if ($link->connect_error){
die("Connection failed: ".$link->connect_error);
}
$sql = "SELECT * FROM product";
$res= $link->query($sql);
while($row = $res->fetch_assoc()){
$_SESSION['item']=$row;
echo '<pre>';
echo print_r ($_SESSION["item"],true);
echo '</pre>';
}
if(in_array("1",$_SESSION['item'])){
echo "found";
}else{
echo "Not found";
}
?>