Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:12:10+00:00 2026-05-25T19:12:10+00:00

I have a rather simple query to work with my ajax app, but it

  • 0

I have a rather simple query to work with my ajax app, but it gives the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘desc, price FROM products WHERE id=’asfasfasf1” at line 1

I’m stumbled by this as I simply can’t see the syntax error anywhere:

echo json_encode($this->query("SELECT name, desc, price FROM products WHERE id='".$id."';"), JSON_FORCE_OBJECT);

query() is as follows:

function query($query){
        $link = mysql_connect($this->host, $this->username, $this->password);
        $connected = mysql_select_db($this->database, $link);
        if(!$connected){
            die("Error: selecting database.");
        }
        $q = mysql_query($query);
        if(!$q){
            return "Error: ".mysql_error();
        }
        $result = mysql_fetch_assoc($q);
        return $result;
    }

Naturally, this is inside an object, but that shouldn’t have anything to do with it. All the fields are correct, database can be connected to since the query() is used multiple times with other code and works well. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:12:10+00:00Added an answer on May 25, 2026 at 7:12 pm

    desc is a keyword in SQL (for sorting in descending order.) If you’re going to use it as a column name, try quoting it:

    $this->query("SELECT name, `desc`, price FROM products WHERE id='".$id."';")
    

    See the MySQL manual on reserved words for an almost identical example, and more details on how to deal with keywords.

    Or you could just rename your column to “description”, say. Much as quoting is the “right” solution, it’s generally helpful to avoid using reserved words as column names if you can.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this rather simple SQL query, but it takes almost a minute to
I have a rather simple PL/SQL query (...) DECODE(upper(Table.Column), 'SOMETHING', '---', TABLE2.COLUMN2) as VALUE
I am using Symfony 2.0.10 with Doctrine 2.1 and have rather simple query (see
This seems rather simple but it has been giving me a headache. I have
I need to construct some rather simple SQL, I suppose, but as it's a
It's a rather simple query but I can't seem to get it done in
We have a rather simple site (minimal JS) with plain html and CSS. It
I will try to keep this as simple as possible. I have a rather
Heavy emphasis on simple. I've never made an installer and I'd rather not have
I'm rather new to WPF, so maybe this is a simple question. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.