Array to string conversion in (cant get it to work)

Posted by user2966551 on Stack Overflow See other posts from Stack Overflow or by user2966551
Published on 2013-11-09T21:45:25Z Indexed on 2013/11/09 21:53 UTC
Read the original article Hit count: 120

Filed under:

ok I am trying to pull a a specific row of data that corresponds to the username logged in. on my page I have started my session but for some reason I cant get the code to work.i keep getting a "Array to string conversion in " on the line " WHERE username = '$_SESSION[user]'");" what am I doing wrong? if I set username = a set username it works but I need it to draw from the session id so it will display different values based on whos logged in.

<?php

 $con=mysqli_connect("localhost","root","xxx","xxxx");
 // Check connection
 if (mysqli_connect_errno())
 {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

 $result = mysqli_query($con,"SELECT * FROM users
 WHERE username = '$_SESSION[user]'");

 while($row = mysqli_fetch_array($result))
 {
 echo $row['username'] . " " . $row['att'];
 echo "<br>";
 }
 ?> 

© Stack Overflow or respective owner

Related posts about php