title: Object of class could not be converted to string
body: <p>I was trying to link the username of logged in user with his age but I'm getting the below error. can anybody help me out? Just help me insert the username with the age, please.</p>
  
  <pre><code>Catchable fatal error: Object of class loggedInUser could not be converted to string 
  </code></pre>
  
  <p>here is the insert query:</p>
  
  <pre><code>&lt;?php
  
  if ( isset( $_POST['submit'] ) ) { 
  require_once("models/config.php");
  securePage($_SERVER['PHP_SELF']);
  
  $age = $_POST["age"];
  $username = $_SESSION["userCakeUser"];
  $stmt = $mysqli-&gt;prepare("INSERT INTO test (username, Age) VALUES (?, ?)");
  
  // TODO check that $stmt creation succeeded
  
  // "s" means the database expects a string
  $stmt-&gt;bind_param("ss",  $username, $age);
  
  $stmt-&gt;execute();
  
  
  $stmt-&gt;close();
  
  mysqli-&gt;close();
  }
  ?&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;form action="" method="post" enctype="multipart/form-data"&gt;
  Age:&lt;input type="text" name="age" required&gt;&lt;br&gt;
  &lt;input type="submit" value="Submit" name="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>
     </p>
  
  <p>and here is what I have inside <code>config.php</code>:</p>
  
  <pre><code>&lt;?php
  require_once("db-settings.php"); //Require DB connection
  
  //Retrieve settings
  $stmt = $mysqli-&gt;prepare("SELECT id, name, value
  FROM ".$db_table_prefix."configuration");   
  $stmt-&gt;execute();
  $stmt-&gt;bind_result($id, $name, $value);
  
  while ($stmt-&gt;fetch()){
  $settings[$name] = array('id' =&gt; $id, 'name' =&gt; $name, 'value' =&gt; $value);
  }
  $stmt-&gt;close();
  
  //Set Settings
  $emailActivation = $settings['activation']['value'];;
  $mail_templates_dir = "models/mail-templates/";
  $websiteName = $settings['website_name']['value'];
  $websiteUrl = $settings['website_url']['value'];
  
  $emailAddress = $settings['email']['value'];
  $resend_activation_threshold = $settings['resend_activation_threshold']['value'];
  $emailDate = date('dmy');
  $language = $settings['language']['value'];
  $template = $settings['template']['value'];
  
  $default_hooks = array("#WEBSITENAME#","#WEBSITEURL#","#DATE#");
  $default_replace = array($websiteName,$websiteUrl,$emailDate);
  
  if (!file_exists($language)) {
  $language = "models/languages/en.php";
  }
  
  if(!isset($language)) $langauge = "models/languages/en.php";
  
  //Pages to require
  require_once($language);
  require_once("class.mail.php");
  require_once("class.user.php");
  require_once("class.newuser.php");
  require_once("funcs.php");
  
  session_start();
  
  //Global User Object Var
  //loggedInUser can be used globally if constructed
  if(isset($_SESSION["userCakeUser"]) &amp;&amp; is_object($_SESSION["userCakeUser"]))
  {
  $loggedInUser = $_SESSION["userCakeUser"];
  }
  
  ?&gt;
  </code></pre>