cant store session variable into database
<p>I have in seassion stored variable. I want to insert session variable and other informations filled through form into table. I got message that it was created but nothing shows in table.</p>

<p>I want to take session variable and store it into "username"
i tried $username=$r['username']; but doesnt work.</p>

<pre><code>&lt;?php
    session_start();
    if($_SESSION['user']==''){
        header("Location:login.php");
    }else{
        $dbh=new PDO('mysql:dbname=mydb;host=127.0.0.1', 'myusername', 'mypassword');


    $sql=$dbh-&gt;prepare("SELECT * FROM users WHERE id=?");
    $sql-&gt;execute(array($_SESSION['user']));
    while($r=$sql-&gt;fetch()){

    $username=$r['username'];  &lt;-im not sure if this is correct.
    $ime=$_POST['ime'];
    $priimek=$_POST['priimek'];
    $email=$_POST['email'];
    $izob=$_POST['izob'];
    $izk=$_POST['izk'];
    $prib=$_POST['prib'];
    $opis=$_POST['opis'];
        $sql = "INSERT INTO profil (ime, priimek, email, izob, izk, prib, opis) VALUES( `username`,`ime` , `priimek ` , `email` , `izob` , `izk` , `prib` , `opis`)";

        try {
            $dbh-&gt;exec($sql);
            echo " created successfully";
        } catch(PDOException $e) {
            echo $sql . "&lt;br&gt;" . $e-&gt;getMessage();
        }
    }

    $conn = null;
}
?&gt;

CREATE TABLE profil(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        username VARCHAR(10),
        ime VARCHAR(10) NOT NULL,
        priimek VARCHAR(10) NOT NULL,
        email VARCHAR(20),
        izob VARCHAR(20),
        izk VARCHAR(10),
        prib VARCHAR(10),
        opis VARCHAR(100),
);
</code></pre>

<p>thanks for help</p>