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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:39:22+00:00 2026-06-18T07:39:22+00:00

I have a php script called via an ajax request each time a user

  • 0

I have a php script called via an ajax request each time a user presses a button that is supposed to get the next 10 rows of a database. When the button is pressed, nothing happens and I get no errors in the console or from the php

$query = $conn->prepare('SELECT name, file_loc, img_id, filter, votes FROM images WHERE user_id=? ORDER BY votes DESC LIMIT ?, 10');
$query->execute(array($user_id, $skip));
$result = $query->fetchAll();

When I go to phpmyadmin, manually fill in the variables, and run the query directly, it runs properly.

In the php when I add echo $skip . ' ' . $user_id;to the end of the script, it shows that all the variables are what they are supposed to be. Additionally if I edit the end of the query to use a static number instead of plugging the variable to read LIMIT 10, 10, then everything works fine (although not being a variable, it can’t increment by 10).

I have no idea why this isn’t running properly but I feel like I’m overlooking something obvious. Any ideas?

  • 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-18T07:39:24+00:00Added an answer on June 18, 2026 at 7:39 am

    When in emulation mode (which is on by default), PDO is substituting placeholders with actual data.
    And with “lazy” binding PDO treats every parameter as a string.
    As a result, the query become

    LIMIT '10', 10
    

    which is obviously wrong syntax that causes query to fail.

    So, you have 2 solutions:
    By turning emulation off (as mysql can sort all placeholders properly)
    Or by binding the number explicitly, like in the Kalpesh’s answer. But don’t forget to set proper type (PDO::PARAM_INT) for this variable.

    To turn emulation off run this code after connect

    $conn->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
    

    and also, to get errors, add this one

    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php script that gets called via an ajax call. Values are
I have a php script that outputs a random image each time it's called.
I have a PHP script that is kicked off via ajax. This PHP script
I have a script that calls a php page via jquery/ajax. The results would
I have a PHP script called customers.php that is passed a parameter via the
I have the following problem: A PHP Script is called via Ajax. The script
I have a PHP script that executes perfectly when called via the browser. It
I have a form that get's processed via jQuery Ajax. Everything works well on
I have the following code in a PHP file called via Ajax (note -
I have the following PHP script being called by AJAX: <?php // file /ajax/loopback.php

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.