php - $result only one row then convert into session -


i trying query 1 single row table 'account'. kind mess mysqli need advice. how can that?

$link = mysqli_connect("localhost","root","","database") or die("error " . mysqli_error($link));  $query = "select * account username='".$user."' , password='".$passcode."' limit 1"; $result = $link->query($query) or die("error " . mysqli_error($link)); $numrow = $result->num_rows; $res = $result->fetch_assoc(); 

after query want copy data session, doing that:

    session_start();       $tableau = array($res['cod_acc'],$res['username'],$res['password']);      $_session['tableau'] = $tableau; 

and after these, how can print data?

    $tableau = $_session['tableau'];      echo "$tableau['username']"; 

from question:

how can print data?

first of need add error_reporting() on in code:

error_reporting(e_all); 

you saving values in array $_session:

$tableau = array($res['cod_acc'],$res['username'],$res['password']);  $_session['tableau'] = $tableau; 

if session array it's not associative array.

so can not result like:

$tableau = $_session['tableau'];  echo $tableau['username']; 

solution:

you can username session array as:

echo $tableau[1]; // username on second index. 

solution 2:

if want associative index need use associative array as:

$tableau = array( "cod_acc"=>$res['cod_acc'], "username"=>$res['username']);  $_session['tableau'] = $tableau; 

now can use need. note removing password field session think not need.

side note:

i don't know why mixing procedural , objected oriented style together.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -