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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:09:18+00:00 2026-06-11T13:09:18+00:00

I am using php to insert element values of a form in MYSQL. My

  • 0

I am using php to insert element values of a form in MYSQL. My form contains 20 different elements, that means

count($_POST)

returns 20. How can I make an INSERT query efficiently in PHP.

  • 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-11T13:09:20+00:00Added an answer on June 11, 2026 at 1:09 pm

    I will extract 20 values one by one then concatenate them again one by
    one. I do not want to follow this method. Do you have some better
    method?

    Yes, you can use foreach. Example below assumes 3 thigs:

    • all of your form fields are text fields,
    • form fields are in the same order as columns in your table
    • form elements (<input>) have the same name attribute as columns names in your table

    It can go like this:

    $sql = 'INSERT INTO table_name VALUES (';
    foreach ($_POST as $key => $value)
        $sql .= mysqli_real_escape_string($value);
    $sql .= ')';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Json to retrieve elements from mysql and insert them into form
How do I modify and insert form elements using PHP? I have a form
How can I insert an image in MySQL and then retrieve it using PHP?
I am trying to run a mysql insert query using php exec with parameters.
I'm using the PHP PDO's to insert and update values in a table. The
I'm using PDO to insert a record (mysql and php) $stmt->bindParam(':field1', $field1, PDO::PARAM_STR); $stmt->bindParam(':field2',
I am using below code to upload excel and INSERT in mysql in php
I tried to insert data into mysql table in server using php server scripting,
Greetings, I'd like to insert html via a form into my database using php.
I'm passing a large dataset into a MySQL table via PHP using insert commands

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.