Jump to content

MySQL error: Unknown column … in 'where clause'


ACBMSE

Recommended Posts

I'm a newbie, can you please help?

I'm getting a mysql error "Unknown column 'E0000001' in 'where clause'"

The id is in the URL: ...user-profile.php?id=E0000001

My Query

$query = mysqli_query($con, "SELECT * FROM UserList WHERE UserID=".$id) or die (mysqli_error($con));

Thank you

Edited by ACBMSE
Link to comment
Share on other sites

16 minutes ago, ACBMSE said:

SELECT * FROM UserList WHERE UserID=".$id)

.. therefore the query being executed is

SELECT * FROM UserList WHERE UserID=E0000001

1 ) String variables in a SQL statement need to be in single quotes otherwise they are thought to be a column name.

2 ) The variable shouldn't be there at all - you should be using a prepared statement and passing the id as a parameter

$query = mysqli_prepare($con, "SELECT * FROM UserList WHERE UserID = ? ");
$query->bind_param('s', $id);
$query->execute();

 

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.