1

How can I select the 'description' row from my 'users' table? I want to just grab the description row depending on what user is logged in.

So far I have this code

$sql = "SELECT description FROM users WHERE uid="$_SESSION['uid']";

but I get this error:

Parse error: syntax error, unexpected '$_SESSION' (T_VARIABLE) in /Applications/XAMPP/xamppfiles/htdocs/login_sys/includes/profile.inc.php on line 19`

Qirel
  • 25,449
  • 7
  • 45
  • 62

3 Answers3

1

That's because your code is syntaxically wrong. The correct code would be this:

$uid = $_SESSION['uid'];
$sql = "SELECT description FROM users WHERE uid='$uid'";

(I put the $_SESSION['uid'] in a variable to avoid the problem with lots of quotes in the query).

However, this solution is also wrong, in that you should never use a variable directly in the database like this, even when it's a session. You should read up on prepared queries, and make sure you use either mysqli_ or PDO as a database-handler in PHP.

junkfoodjunkie
  • 3,168
  • 1
  • 19
  • 33
  • He could also do `$sql = "SELECT description FROM users WHERE uid=" . $_SESSION['uid'];` – Jaime Oct 28 '16 at 23:58
0

you are getting this error beacause you are missing one " at end of query

$sql = 'SELECT description FROM users WHERE uid="$_SESSION['uid']"';
but always use prepare queries or pdo's as you query this is vulnerable to sql
injection 
Hassan Tahir
  • 134
  • 9
0

this should work $sql = "SELECT description FROM users WHERE uid='$_SESSION[uid]'";

Matas Lesinskas
  • 414
  • 6
  • 13