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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:58:15+00:00 2026-06-09T03:58:15+00:00

Along the same lines of proper coding of my queries to work with prepared

  • 0

Along the same lines of proper coding of my queries to work with prepared statements, I have this query:

$sql = "SELECT *
        FROM photos
        WHERE g_id = ?
        LIMIT $curPage,".$totalPix;
$result = $conn->query($sql) or die(mysqli_error());
$row = $result->fetch_assoc();

The question here is, should I use the prepared statement placeholders for $curPage and $totalPix and if so, would I do it this way:

$sql = "SELECT *
        FROM photos
        WHERE g_id = ?
        LIMIT ?,".?;
$gid = $i; $lm = $v1; $mt = $v2 
$stmt = $conn->prepare($randPic);
$stmt->bind_param('iii', $gid, $lm, $mt);
$stmt->bind_result($p_fname);
$stmt->execute();
$stmt->store_result();
$stmt->fetch();

…or are the variables $curPage and $totalPixnot leaving the query open to SQL injection? Many thanks in advance!

  • 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-09T03:58:18+00:00Added an answer on June 9, 2026 at 3:58 am

    You are using the ? on the right place (since it can only be used for variable binding). However it is not safe to simply place $curPage or $totalPix in your query. I am assuming they have to be integers, so it is not really hard to make that safe.

    Use intval($curPage) and intval($totalPix) to be certain they are.

    However, if you want to allow strings it is a bit more difficult. Not sure if it is thé solution, but my bet is to ‘whitelist’ possible options by checking if it is something you designed it for.

    For instance: SELECT * FROM sometable WHERE $somevar = ? The variable ($somevar) could still be '1 --' which would return all the rows. But most likely you mean $somevar = ‘id’ or $somevar = ’email’. Which can easily be checked by some if statements and it wouldn’t hurt performance. Maybe a little typing, but if your not in the mood to type I suggest using some framework for queries or ORM of some kind.

    if ($somevar !== 'id') exit('Cannot find entries'); at the start of the function or page

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

Sidebar

Related Questions

This question is along the same lines as Retrieving Device Context from .NET print
Along the same lines as this question , I want to call acts_as_reportable inside
Along the same lines as to what was described in conversion to ‘size_t’ from
Along the same lines as this question - How do I clone all remote
Despite many posts I have looked through being of along the same lines as
I have an STL list of pointers, along with another pointer of the same
I have a long string, the format will be same of this string but
Somewhere along the line from the DB to the application, this: sauté is getting
Got a complex SELECT query, from which I would like to insert all rows
Along the same lines that for java centric applications, Play framework is stateless and

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.