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 8803287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:18:07+00:00 2026-06-14T01:18:07+00:00

Im having this query: $query = $db->query(SELECT posts.post_topic_id, posts.post_content, posts.post_id, posts.post_date, posts.post_by, posts.post_votes_total, posts.post_suggested_amount,

  • 0

Im having this query:

$query = $db->query("SELECT

                      posts.post_topic_id,
                      posts.post_content,
                      posts.post_id,
                      posts.post_date,
                      posts.post_by,    
                      posts.post_votes_total,
                      posts.post_suggested_amount, 
                      posts.post_accepted,
                      posts.post_last_edited,
                      posts.post_edit_sum,
                      users.user_id,
                      users.username

                    FROM
                      posts

                    JOIN
                      users
                    ON
                      posts.post_by = users.user_id
                    WHERE
                      posts.post_topic_id = :topic_id
                    ORDER BY
                      :sort
                    LIMIT :start , :per_page
                  ");

$query->bindParam(':topic_id', $topic_id, PDO::PARAM_INT);
$query->bindParam(':sort', $sort, PDO::PARAM_STR);
$query->bindParam(':start', $start, PDO::PARAM_INT);
$query->bindParam(':per_page', $per_page, PDO::PARAM_INT);
$query->execute();

But it wont execute and give me and error instead:

exception ‘PDOException’ with message ‘SQLSTATE[42000]: Syntax error or access violation: 1064 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 ‘:topic_id ORDER BY posts.post_id ASC ‘ at line 25’ in C:\htdocs\lr\topic.php:577 Stack trace: #0 C:\htdocs\lr\topic.php(577): PDO->query(‘SELECT???? …’) #1 {main}

If I don’t prepare the statements, and I use the normal variables, the query executes just fine.

What’s my mistake?

  • 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-06-14T01:18:08+00:00Added an answer on June 14, 2026 at 1:18 am

    You mix up methods for prepared statements and simple queries. The bindParam() method just relates to prepared statements. On its own, the query() method tries to execute the given query immediately, which fails, because the parameters have not been substituted.

    To solve this, just change to prepared statements all along by using

    $query = $db->prepare("SELECT ... " );
    

    and then execute after binding all variables

    $query->exec();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi guys I am having issue I have this query: SELECT * FROM useraccount
Having tried this query a million different ways, I can't seem to SELECT 'count_lonely_vehicles'
I'm having this Mysql query, It works: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT
I am having this Linq To SQL query which is taking Customer Category from
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I am having a real pain in converting this query expression into my LINQ
I'm having a problem with this query that takes several seconds to complete. I
I'm having trouble getting any information to display from this query. Anyone know where
I'm having trouble wrapping my head around how to write this query. A hypothetical
I'm having this link statement: List<UserGroup> domains = UserRepository.Instance.UserIsAdminOf(currentUser.User_ID); query = (from doc in

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.