Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I am having trouble getting my script to function properly. I have written a script that is supposed to go out to the database and retrieve a profile picture based on the username of the current user. I keep getting an error.

Here is the full error report from my domain host:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'HansBresko' in 'where clause'' in /home/www/mujomusic.net/WDV341/PHP-Final/admin-homepage.php:23 Stack trace: #0 /home/www/mujomusic.net/WDV341/PHP-Final/admin-homepage.php(23): PDOStatement->execute() #1 {main} thrown in /home/www/mujomusic.net/WDV341/PHP-Final/admin-homepage.php on line 23

and here is the code for the script:

<?php

session_start();

if(isset($_SESSION["username"]))
{
     //do nothing
}

else
{
     header("location:admin-login.php");
}

include 'session_timeout.php';

include 'connect.php';
//login_success.php

$currentuser = $_SESSION["username"];

$resultX = $conn->prepare("SELECT profile_pic FROM admin_credentials WHERE username=$currentuser");
$resultX->execute();

?>


I have tried everything and it just won't work. Please help!

What I have tried:

I have tried multiple documented solutions but nothing seems to work.
Posted
Updated 13-Dec-17 1:36am

1 solution

username is a reserved SQL keyword. You should avoid using such as table or column name. To avoid the error you must quote the name or (for column names) prepend the table name:
PHP
$resultX = $conn->prepare("SELECT profile_pic FROM admin_credentials WHERE admin_credentials.username=$currentuser");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900