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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:27:18+00:00 2026-06-12T15:27:18+00:00

I have a selection of post fields which are submitted through a web form:

  • 0

I have a selection of post fields which are submitted through a web form:

$_POST['first_name'];
$_POST['last_name'];
$_POST['house_number'];
$_POST['postcode'];

etc

I would like to add the following code structure to each one:

if (isset($_POST['first_name'])) {
    $first_name = mysql_prep($_POST['first_name']);
}

How can I use a loop to achieve this to save having to repeat myself multiple times?

Thanks

  • 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-12T15:27:19+00:00Added an answer on June 12, 2026 at 3:27 pm

    You can use PHP’s extract() function to do this for you.

    extract($_POST);
    // you now have a variable for every key in $_POST
    

    If you only want a certain list of keys, and not the full array, you can also use variable-variables (a variable with two leading $, such as $$var):

    $keysToExtract = array('first_name', 'last_name');
    foreach ($keysToExtract as $key) {
        $$key = $_POST[$key];
    }
    // you now have $first_name and $last_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Spatial Selection implemented on Map in my Web Application, which selects the
I have a form-1 which has 4 fields. when the user inputs data in
Our site's UI displays read-only text fields which have mouse-click handlers -- when the
I have a contact form on my website, which actually works :D The problem
I have an autosuggest done in PHP which on selection will provide to me
var d = $('form[name=aspnetForm]').formSerialize(); $.ajax({ type: POST, data: d }); I have a ListBox
I have a question regarding checkboxes. <form method=post> I speak the following languages: <input
I have a model Post which belongs_to one Section . There are two different
The form below can contains different elements of text fields, drop down and selection
I have a form which posts data to the same page. Based on the

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.