Jump to content

Problem with invalid column on select


Go to solution Solved by mac_gyver,

Recommended Posts

Hi,

 

I am using GET to receive a variable from a url and then selecting from the DB where I find a match on that value. The problem, which I have never seen before the error tells me that the value is being used to find the column name:

 

Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'car'

 

Here is the code, the get value is car - why is it doing this?!

 

$type = $_GET['type']; $userid = $_SESSION['user_session'];  //item per page$limit = 5;         $page = filter_input(INPUT_GET, 'p', FILTER_VALIDATE_INT, array(    'options' => array('min_range' => 1, 'default' => 1)));         $sqlContent="SELECT make, model, year, rideid FROM ride1 WHERE type = $type";
 
 
Thanks,
 
G
Link to comment
https://forums.phpfreaks.com/topic/297974-problem-with-invalid-column-on-select/
Share on other sites

  • Solution

you might want to use a prepared query to get the $type value into the sql statement in order to prevent sql injection or errors if the value contains sql special-characters. using a prepared query to provide the $type value, would have also prevented the original error you are getting.

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.