title: storing username from session to database while form submission using php
body: <p>I have a simple question,</p>
  
  <p>I have a login and workspace area.</p>
  
  <p>After the user logs in It shows the username of the logged in user at workplace as what I wanted. Now my problem is when user finish filling form available in his workspace the form is then stored in database also i need the username that is coming from session also get stored to the database.</p>
  
  <p>here is code that is storing username and maintaining session after user reach at workspace after login:</p>
  
  <pre><code>&lt;?php
  require_once($_SERVER['DOCUMENT_ROOT'].'/MainProject/connect/auth.php');
  session_start();
   ?&gt;
  </code></pre>
  
  <p>The final version of the updated insert file :</p>
  
  <pre><code> //This code is included to check session and store username
   &lt;?php
   require_once('..\connect\auth.php');
  // session_start();
  $usern = $_SESSION['SESS_FIRST_NAME'];
   ?&gt;
  &lt;?php
  mysql_connect('localhost','root','');
  mysql_select_db('main_project') or die (mysql_error());
  
  if(isset($_POST['WID'])){
  for ($ix=0; $ix&lt;count($_POST['WID']); $ix++)
  {
      $WID = mysql_real_escape_string(@$_POST['WID'][$ix]);
      $website = mysql_real_escape_string(@$_POST['website'][$ix]);
  
      //var_dump("&lt;pre&gt;", $_POST['cat']); die();   // Debugger for checking cat counter.
      // $cat = implode(",", mysql_real_escape_string($_POST['cat'][$ix]));       
  
      if(is_array(@$_POST['cat'][$ix]))
      $cat = mysql_real_escape_string(implode(',', @$_POST['cat'][$ix]));
      else
      $cat = mysql_real_escape_string(@$_POST['cat'][$ix]);   
  
      $email = mysql_real_escape_string(@$_POST['email'][$ix]);
      $cform = mysql_real_escape_string(@$_POST['cform'][$ix]);
      $contactp = mysql_real_escape_string(@$_POST['contactp'][$ix]);
      $contacts = mysql_real_escape_string(@$_POST['contacts'][$ix]);
      $fax = mysql_real_escape_string(@$_POST['fax'][$ix]);
      $Ctype = mysql_real_escape_string(@$_POST['Ctype'][$ix]);
     $usern = mysql_real_escape_string(@$_POST['usern'][$ix]);
  
      $sql_res = mysql_query("INSERT INTO website_01data (WID,website,cat,email,cform,contactp,contacts,fax,Ctype,TimeStamp,usern) 
      VALUES ('".$WID."', '".$website."', '".$cat."', '".$email."','".$cform."', '".$contactp."', '".$contacts."', '".$fax."', '".$Ctype."', Now(), '".$usern."' )");
  
  $sql_res = mysql_error();   
  
  }//end for..
  
  echo "&lt;p&gt;&lt;span style=\"color: red;\"&gt;Thank You; your records are sent to database. DO NOT REFRESH THE PAGE or data will be sent again.&lt;/span&gt;&lt;/p&gt;"; 
  
  }
  ?&gt;
  </code></pre>