I was wondering if anyone could shine a light on how to read from a database and pass it on to a sessions variable. I have tried with a product id and get but it did not work.
I'm looking for the basics on how to approach the issue.
I assume that you need to read from MySQL Database (for example).
First thing to do is reading PHP/MYSQL documentation.
http://www.w3schools.com/php/php_mysql_intro.asp
Second thing is to read about PHP Sessions.
http://www.w3schools.com/php/php_sessions.asp
And for example some code:
// Connect to MySQL Database and select all records from your_table
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = $conn->prepare("SELECT * FROM your_table");
$query->execute();
if($query == TRUE) {
// query success
}
To store information in $_SESSION
variable you need to:
Call session_start();
before accessing this variable
$_SESSION['your_var'] = 'your_value';