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

  • Home
  • SEARCH
  • 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 7005767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:23:34+00:00 2026-05-27T21:23:34+00:00

$sql=’SELECT phrase,english FROM static_site_language WHERE page=?;’; $pds=$database->pdo->prepare($sql); $pds->execute(array($_POST[‘languagepage’])); The above code runs fine. However

  • 0
$sql='SELECT phrase,english FROM static_site_language WHERE page=?;';
$pds=$database->pdo->prepare($sql); $pds->execute(array($_POST['languagepage']));

The above code runs fine. However I need to put another variable into the prepare statement. I have tried the following but it doesn’t seem to work:

$sql='SELECT phrase,? FROM static_site_language WHERE page=?;';
$pds=$database->pdo->prepare($sql); $pds->execute(array($_POST['language'],$_POST['languagepage']));

I know $_POST[‘language’] (from printing it) only contains the word ‘english’.
Is it possible to put a prepare variable in this part of a select?

thx

  • 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-27T21:23:35+00:00Added an answer on May 27, 2026 at 9:23 pm

    Query parameters can take the place of only a constant value — not a column name.

    All columns and tables must be named at the time you prepare a query, you can’t postpone choosing columns to the subsequent execute step.

    When you want user input to determine a column name, use a Whitelist Map to limit user input to valid choices. The keys of the map array are the legal user inputs. The values of the map array are the strings you want to use in the SQL query, in this case column names.

    $lang_col_map = array(
      "DEFAULT" => "english",
      "en"      => "english",
      "es"      => "spanish"
    );
    $lang_col = $lang_col_map[ $_POST["language"] ] ?: $lang_col_map[ "DEFAULT" ];
    
    $sql='SELECT phrase,$lang_col FROM static_site_language WHERE page=?;';
    $pds=$database->pdo->prepare($sql); 
    $pds->execute(array($_POST['languagepage']));
    

    This way you can be sure that only values in the $lang_col_map can become part of the SQL query, and if the user tries to send anything tricky in the http request, it’s ignored because it doesn’t match any key of that map. So the query is safe from SQL injection.

    See my presentation SQL Injection Myths and Fallacies for more information.

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

Sidebar

Related Questions

SQL: SELECT u.id, u.name, isnull(MAX(h.dateCol), '1900-01-01') dateColWithDefault FROM universe u LEFT JOIN history h
SQL Server 2005 query is as follows...... SELECT ClgId FROM IdMaker_DB WHERE Course =
SQL query: select ApplicationNumber,pri_indicator,count(*) from customer group by ApplicationNumber,pri_indicator How do I do this
SQL: SELECT COUNT(*) FROM bb_posts post LEFT JOIN bb_topics topic ON topic.topic_id = post.topic_id
SQL 1: select * from t1 join t2 on t1.f1 = t2.f2 SQL 2:
SQL: SELECT uFName, uLName, listTitle, listPropPrice, listCmt, listDt, mFName, mLName, moAmt, moDtOff FROM User
SQL Server 2000 I backup a table like below: select * into bkp_table from
SQL Server 2000 Standard, Windows 2003 My coworker removed 'BUILTIN\Administrators' group from SQL Server
SQL Server 2005/2008 Express edition has the limitation of 4 GB per database. As
SQL Server 2005 I have 10 million rows in DB, and run a select

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.