0

hi how can i fetch data from the database and stroe it into session variable.
my code:

   $sql = "SELECT password, fullname, username, active FROM ".$mysql_table." WHERE (username = :username OR email = :username) AND password = :password";
   $statement = $pdo->prepare($sql);
   $statement->bindValue(':username', $_POST['username']);
   $statement->bindValue(':password', md5($_POST['password']));
   $statement->execute();
   $result = $statement->fetchAll(PDO::FETCH_ASSOC);
    if (count($result) == 1)
    {

      if (session_id() == "")
      {
         session_start();
      }

      $_SESSION['username'] = ;
      $_SESSION['fullname'] = ;
      $_SESSION['expires_by'] = time() + $session_timeout;
      $_SESSION['expires_timeout'] = $session_timeout;
      $rememberme = isset($_POST['rememberme']) ? true : false;
      if ($rememberme)
      {
         setcookie('username', $_POST['username'], time() + 3600*24*30);

      }
      if(!isset($_COOKIE['redirect'])) {
      $redirect_page_no = './index.php';
      header('Location: '.$redirect_page_no);
      exit;
      }
      else
      {
      $redirect_page = $_COOKIE["redirect"];
      header('Location: '.$redirect_page);
      exit;
      }
   }

in the line 15 and 16 i want to store the username and fullname value fetched from the database.

$_SESSION['username']
$_SESSION['fullname']

how do i do it?

2
Contributors
2
Replies
27
Views
3 Years
Discussion Span
Last Post by Eagle.Avik
0

I suppose something like this should work:

$_SESSON['username'] =  $result[0]['username'];
$_SESSON['fullname'] =  $result[0]['fullname'];
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.