Note that there are some explanatory texts on larger screens.

plurals
  1. POSet userid into the session array how?
    primarykey
    data
    text
    <p>Hello I am posting maybe 4th question about this issue but nobody can help me so far, so let's start from the begining, what I need is simple I need to: Set userID variable from column name "userID' inside table named "users" into the Sessions array: $_SESSION['userID']</p> <p>here is my login page code: </p> <pre><code>&lt;?php session_start(); include_once("config.php"); //include the settings/configuration ?&gt; &lt;?php if( !(isset( $_POST['login'] ) ) ) { ?&gt; &lt;?php //else look at the database and see if he entered the correct details } else { session_start(); $usr = new Users; $usr-&gt;storeFormValues( $_POST ); if( $usr-&gt;userLogin() ) { header( 'Location: cursos.php' ) ; $_SESSION["loggedIn"] = true; $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['password']; </code></pre> <p>and here is my user class which operates the function login: </p> <pre><code>public function userLogin() { $success = false; try{ $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1"; $stmt = $con-&gt;prepare( $sql ); $stmt-&gt;bindValue( "username", $this-&gt;username, PDO::PARAM_STR ); $stmt-&gt;bindValue( "password", hash("sha256", $this-&gt;password . $this-&gt;salt), PDO::PARAM_STR ); $stmt-&gt;execute(); $result = $sth-&gt;fetch(PDO::FETCH_ASSOC); $success = true; if ($result!==false) { // Check there is a match $_SESSION['userID']= $result['userID']; } $success = true; $con = null; return $success; }catch (PDOException $e) { echo $e-&gt;getMessage(); return $success; </code></pre> <p>The code is working fine I just want to add addition to it which will get the userID value from the column of the users table inside the database ans store it to the $_SESSION['userID'] after user is loged in.</p> <p>So any idea how to reach this goal in my code ? thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload