php mysql array to string conversion error -


this driving me crazy...

i'm trying pull int value database (mysql), reason error:

notice: array string conversion in c:\xampp\htdocs\ajax\myjobs.php on line 33

this points html try echo $deptnum:
<h1><?php echo $deptnum; ?></h1>

here's of php code:

<?php    require ("config.php");   include ("menu.php");     /* config.php contains code connect database , works fine */    /* check if value user_name exists */   if (isset($_session['user_name'])) {        $the_user_name = $_session['user_name'];        /* fyi, pull correct username, in case: "ussatjodo" */        /* pull value database */       $result = $db->prepare("select `dept` `users` `username` = :uname");       $result->execute(array(':uname' => $the_user_name));       $deptnum=$result->fetch();     } else {       $the_user_name = '';   }  ?>  <h1><?php echo $deptnum; ?></h1> 

and here table "users"

enter image description here

to sum up:

  • $_session['user_name'] correctly pulls username (example: 'ussatjodo');
  • all i'm trying correct value column 'dept' in case of username "ussatjodo", 'dept' 1
  • currently error telling me there error i'm trying convert array string.

fetch() returns array indexed table column names. try:

echo $deptnum['dept']; 

php >= 5.4.0:

$deptnum = $result->fetch()['dept']; 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -