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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:05:09+00:00 2026-05-23T20:05:09+00:00

I have a form that is generated dynamically. The end users will be able

  • 0

I have a form that is generated dynamically. The end users will be able to submit employee details to the database. So array $fname will contain all first names, $lname all last names ect. The arrays are then inserted into MySQL like so:

   $query = "INSERT INTO workers (date_added, department,fname, lname, rank)
   VALUES ";
    $fname = count(fname);
    for($i=0; $i<$employee_count; $i++) {
    $query .= "(NOW(),'$department','{$fname[$i]}','{$lname[$i]}','{$rank[$i]}'),\n";
  }

This works great until we have dangerous characters like single quotes e.g MC’Mahon, which makes the query to fail. I cannot use many normal functions such as mysqli_real_escape_string() since this is an array.
Is there a way to sanitize the array i.e escape any dangerous characters inside the arrays so that I sanitize each array before pushing it into them for loop that splits each array into strings that are then entered into MySQL?

  • 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-23T20:05:10+00:00Added an answer on May 23, 2026 at 8:05 pm

    You could use array_map before your for loop. That function applies a callback to each value of the array. In this case, the callback would be mysqli_real_escape_string.

    $fname = array_map('mysqli_real_escape_string', $fname);
    $lname = array_map('mysqli_real_escape_string', $lname);
    $rank = array_map('mysqli_real_escape_string', $rank);
    

    Update based on comments below:

    To use mysqli_real_escape_string in procedural mode, you need to pass the "link" so you need to create a custom function:

    function array_map_callback($a)
    {
      global $dbc;
      
      return mysqli_real_escape_string($dbc, $a);
    }
    
    $fname = array_map('array_map_callback', $fname);
    $lname = array_map('array_map_callback', $lname);
    $rank = array_map('array_map_callback', $rank);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dynamically generated form that I would like to submit using Ajax.
I have a form that is dynamically generated, and has dynamically generated id's (and
I have a drop down list that is dynamically generated using a mySQL database
i have a form that is generated dynamically. the plan is to generate it,
I have a form representing a survey that is dynamically generated based on some
Essentially, I have a dynamically generated local HTML form that I would like to
I have a form that uses jQuery to submit an ajax post and it
I have the following dynamically generated array: var myArray = (0% { left:74px; top:202px;
I have a page that contains a form, where part of it is dynamically
I have a form generated dynamically with the method .append() of jQuery. I can

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.