Q:

How to insert session username into mySql database

I'm trying to write a program where the user adds data into the database and the username of the user is also entered without doing it manually.
This is the php code
$user->createSession(array(
             'title' => Input::get('title'),
             'start_date' => date('Y-m-d H:i:s', strtotime(Input::get('start_date'))),
             'end_date' => date('Y-m-d H:i:s', strtotime(Input::get('end_date'))),
             'passcode' => (Input::get('passcode')),
             'username' => (Input::get('username'))
         ));

This is the htlml
<form class="session" action="" method="POST" >
  <div class="input-group">

<label for="title" ><span class="input-group-addon" id="basic-addon1">Title</span></label>

<input type="text" id="username" name="title" class="form-control" value = "<?php echo escape(input::get('title')); ?>" placeholder="Title" autocomplete="on" required> 
  </div>

<div id="datetimepicker" class="input-append date">
    <input type="text" name="start_date" placeholder="start date"></input>

  <span class="add-on">
    <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
  </span>
</div>

<div id="datetimepicker1" class="input-append date">
    <input type="text" name="end_date" placeholder="end date"></input>
  <span class="add-on">
    <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
  </span>
</div>

  <label for="passcode" class="input-group">Pass-code (optional)</label>
    <input type="passcode" id="passcode" name="passcode" class="form-control" placeholder="Passcode" autocomplete="off" >

    <br>
    <input type = "hidden" name = "username" value = "<?php echo escape($user->data()->username); ?>">

<button class="btn btn-lg btn-primary" type="submit">Create</button>

It adds everything into the database except the username session. I'm not sure what to do. I also tried removing:
<input type = "hidden" name = "username" value = "<?php echo escape($user->data()->username); ?>">

And did:
$user->createSession(array(
         'title' => Input::get('title'),
         'start_date' => date('Y-m-d H:i:s', strtotime(Input::get('start_date'))),
         'end_date' => date('Y-m-d H:i:s', strtotime(Input::get('end_date'))),
         'passcode' => (Input::get('passcode')),
         'username' => $user->data()->username
     ));

This is the database code as requested
session_start();

$GLOBALS['config'] = array(
    'mysql'     => array(
    'host'      => 'localhost', 
    'username'  => 'root', 
    'password'  => '', 
    'db' => 'coursework'),
        //remember me
    'remember' => array('cookie_name' => 'hash', 'cookie_expiry' => '604800'),

'session' => array('session_name' => 'user', 'token_name' => 'token'));

spl_autoload_register(function($class) {
    require_once 'classes/'.$class.'.php';
});

EDIT
This code inserts data into the database
 public function createSession($fields = array()){
    if(!$this->_db->insert('sessions', $fields)){
        throw new Exception ("there was a problem adding a session");
    }
}

Everything else works, the db connection works and the data is entered into the db fine but the username field is empty. The sessions being created is something else like subjects.
Connects to the DB
function __construct() {
    try {
        $this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host') .';dbname=' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password'));
        //echo 'connected';
    } catch (PDOException $e) {
        die($e->getMessage());
    }

}

A:

How to insert session username into mySql database

You need to connect to an actual database with your configuration information,.

PDO is nice for this:
 $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

You need to insert into the database, preferrably using prepared statements.

There are lots of decent answers on how although I like mixing it up with the prepared statement article wherea you should be executing an array of variables into the prepared query.

Get the session information

You can probably figure out how to do it. Maybe there are some other information?
$someValue = ""; // Just some random value.
$someSessionValue = ""; // Extract from session. Probably $_SESSION['stuff'] or similar.

Finally, insert the extracted information.

Something like this should do, take a better look on the links or do a proper search:
$sql = $dbh->prepare("INSERT INTO tablename(column1, column2) VALUES (?, ?)");
$sql->execute(array($someValue, $someSessionValue));

If you wish to make this happen automatically then you just put this into a method that you make your code call automatically when some action is triggered.

