without running this code dump myself, the first thing i see is that it appears your issue is that your variable $mygrid is out of scope of the SELECT statement on line 45.
I'm a bit rusty on my PHP but it looks like you've declared your varaible inside a nested if statement or the else statement which keeps it within the scope of that if/else
if(isset($_SESSION['uid']))
{
$myuid1 = $_SESSION['uid'];
$test1 = $_SESSION['type'];
if($test1 == "0")
{
$myuid1 = $_SESSION['uid'];
$mygrid1 = "0";
}
elseif($test1 == "3")
{
$mygrid1 = $_SESSION['uid'];
$myuid1 = "0";
}
}
else
{
$myuid1 = "0";
$mygrid1 = "0";
}
You are trying to access the variable $mygrid outside the scope of that if/else statement which is why you are getting an undefined error.
Move the variable declaration mygrid1 outside the
if(isset
block and then it should be within scope for the select statement to have it defined.
So something like this
$mygrid1 = "DECLARE HERE";
if(isset($_SESSION['uid']))
{
}
else
{
}