This is driving me crazy...
I'm simply trying to pull an INT value from my database (MySQL), but for some reason i get this error:
Notice: Array to string conversion in C:\xampp\htdocs\ajax\myjobs.php on line 33
this points my html where I try to echo $deptnum:
<h1><?php echo $deptnum; ?></h1>
Here's some of my PHP code:
<?php
require ("config.php");
include ("menu.php");
/* config.php CONTAINS CODE TO CONNECT TO DATABASE AND IT WORKS FINE */
/* Check if a value for user_name exists */
if (isset($_SESSION['user_name'])) {
$the_user_name = $_SESSION['user_name'];
/* FYI, THIS DOES PULL THE CORRECT USERNAME, IN THIS CASE: "ussatjodo" */
/* pull value from database */
$result = $db->prepare("SELECT `dept` from `users` WHERE `username` = :uname");
$result->execute(array(':uname' => $the_user_name));
$deptnum=$result->fetch();
} else {
$the_user_name = '';
}
?>
<h1><?php echo $deptnum; ?></h1>
And here is the table "users"

TO SUM IT UP:
- $_SESSION['user_name'] correctly pulls a username (example: 'ussatjodo');
- All I'm trying to do is get the correct value for column 'dept' which in the case of username "ussatjodo", the 'dept' would be 1
- Currently the error is telling me there is an error that I'm trying to convert an array to string.
fetch()will not return an array.