I am trying to query my database to get a message to display to the user. However it triggers the unknown error line – if($ErrMsgRes === FALSE) instead of returning the value expected.
($db_conn is initiated as a PDO object in the included file.)
include_once __DIR__ . '/resources/system/system.db_conn.php';
for($f = 1; $f<=$_GET['lfec']; $f++){
try{
//Query to determine is user is authorized.
$ErrMsgQry = 'Select A.process_id, A.error_id, A.msg_status, A.msg_effective_date, A.error_msg_heading, A.error_msg_body from systbl_SYS_standard_error_messages A Where A.process_id=:pid AND A.error_id=:eid AND A.msg_status = \'A\' Limit 1';
//Query Parameter )
$ErrMsgParam = ['pid'=>$_GET['p'.$f-1], 'eid'=>$_GET['m'.$f-1]];
//Prepare PDO Query to accept parameters
$ErrMsgTest = $db_conn->prepare($ErrMsgQry);
//Execute PDO Query with parameters
$ErrMsgTest -> execute($ErrMsgParam);
//Results of the query
$ErrMsgRes = $ErrMsgTest->fetch();
if($ErrMsgRes === FALSE){
array_push($errorMsg, "An unknown error occured. Please try again. ");
}else{
$M9638527412222 = '<strong>' ;
$M9638527412222 .= $ErrMsgRes['error_msg_heading'] ;
$M9638527412222 .= '</strong> — ' ;
$M9638527412222 .= $ErrMsgRes['error_msg_body'] ;
$M9638527412222 .= ' <em>(' . $ErrMsgRes['process_id']. '\\' . $ErrMsgRes['error_id'] . ')</em>';
array_push($errorMsg, $M9638527412222);
}
I tried to query the database with the actual data that I was passing via binds, which results in this SQL:
Select A.process_id, A.error_id, A.msg_status, A.msg_effective_date, A.error_msg_heading, A.error_msg_body from systbl_SYS_standard_error_messages A Where A.process_id='sys.login.validate' AND A.error_id='userid2bad' AND A.msg_status = 'A' Limit 1
Which returns the expected result.
What am I doing wrong?