Using Session Variable in SQL query
Hi guys, I have a problem with this query.
It keeps giving me this error code: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens.
if(isset($_POST['button']) && $_POST['button'] == 'submitReport')
$conn = DatabaseManager::getConnection();
$sql = "INSERT INTO report (serviceName, branchId, branchName) VALUES (:serviceName, :'".$_SESSION['branchId']."', :'".$_SESSION['branchName']."')";
$s = $conn->prepare($sql);
$conn = null;
catch (PDOException $e)
$error = 'There was an error while submitting the new service detail, Please try again later.' . $e->getMessage();
if($s->rowCount() == 1)
$output = 'New service detail successfully submitted';
$error = 'Unable to perform your request now, Please try again later.';
What am I doing wrong? Please note that the two session variables used are actively working on their respective page of usage. I'm suspecting the usage of the session variables in terms of binding the value. I need help please because the query works when session variables weren't used. Also, please note that it is the index page has the code above and processes the information from the report form on another page. thanks.
NB: I have session_start() running actively on all my pages.