I am trying to debug a weird issue. I have a query which joins several tables to pull out various information to populate some emails that are sent out. Whenever I try to generate some test emails to verify the code is working, one of the emails is produced without any data in it due to this query issue.
Here is the function which runs the query:
function getSData($id,$uid)
{
global $sql;
echo "PID: ".$id." | UID: ".$uid."</br>";
if ($pd_stmt = $sql->prepare("select t1.Name,t2.SDate,t2.DCode,t3.Quantity,t2.Location,t3.Cost from seminar_events t2 inner join seminars t1 on t2.SID = t1.ID inner join cart_list t3 on t2.ID = t3.PID where t2.ID = ? and t3.CID = ?;"))
{
if ($pd_stmt->bind_param('ii',$id,$uid))
{
if ($pd_stmt->execute())
{
$pd_stmt->bind_result($sname,$sdate,$dcode,$qty,$slocale,$cost);
$pd_stmt->fetch();
echo "Array:";
print_r(array("Name"=>$sname,
"SDate"=>$sdate,
"DCode"=>$dcode,
"Quantity"=>$qty,
"Local"=>$slocale,
"Cost"=>number_format((float)$cost)));
} else{
echo $sql->error;
}
} else{
echo $sql->error;
}
} else{
echo $sql->error;
}
}
Here is the PHP output:
103 //from an earlier echo checking the value of $pID just before this function is called and is passed as the first arg
PID: 103 | UID: 24
Array:
If I take this query and the values above and substitute them in for the ? parameters in the query and run it in PHPMyAdmin I get the records I expected.