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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:46:42+00:00 2026-06-08T13:46:42+00:00

I have the following code to escape posted data: if (isset($_POST[‘submitted’])) { $trimmed_post =

  • 0

I have the following code to escape posted data:

if (isset($_POST['submitted'])) {
    $trimmed_post = array_map('trim', $_POST);

    $bk = mysqli_real_escape_string($dbc, $trimmed_post['bk_id']);
    $ad = mysqli_real_escape_string($dbc, $trimmed_post['address']);
    $ti = mysqli_real_escape_string($dbc, $trimmed_post['bkTitle']);
    $ta = mysqli_real_escape_string($dbc, $trimmed_post['tags']);
    $de = mysqli_real_escape_string($dbc, $trimmed_post['description']);

but I would prefer to do this – it’s neater:

list($bk, $ad, $ti, $ta, $de) = array_map(function ($x) {
    return mysqli_real_escape_string($dbc, $x);
}, $trimmed_post);

I’m using MySql 5.5.16, but it returns “Undefined variable: dbc”.

I suspect it is a ‘closure’ issue. How can I pass $dbc into my lambda pl?

  • 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-08T13:46:44+00:00Added an answer on June 8, 2026 at 1:46 pm

    You can use the use keyword.

    list($bk, $ad, $ti, $ta, $de) = array_map(function ($x) use ($dbc) {
        return mysqli_real_escape_string($dbc, $x);
    }, $trimmed_post);
    

    But honestly, you should be using Prepared Statements.

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

Sidebar

Related Questions

I have following code for inserting data into database using PDO. It inserts data
I have following code: def whatever(url, data=None): req = urllib2.Request(url) res = urllib2.urlopen(req, data)
Hello I have the following php code here: $username = trim(mysql_real_escape_string($username)); $password = md5(trim(mysql_real_escape_string($password)));
Supposed I have the following code: <html:link onclick=jQuery('#add').data('name','${name}').dialog('open'); href=#> And with this, if ${name}
I have the following code: function dbPublish($status) { global $dbcon, $dbtable; if(isset($_GET['itemId'])) { $sqlQuery
I have the following code: public function ajax() { // Contains results $data =
I have the following code which is meant to cycle through names submitted on
I have drawn up the following PHP code which processes the data from a
I have the following code snippet that builds chained select boxes based on data
i have a problem with the following code, apperantly i need to somehow escape

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.