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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:35:35+00:00 2026-06-15T21:35:35+00:00

<?php $_POST[‘aantal’] = 4; $_POST[‘begin’] = 10; $iets = $_POST[‘aantal’] + $_POST[‘begin’]; $ietsanders =

  • 0
<?php
$_POST['aantal'] = 4;
$_POST['begin'] = 10;

$iets = $_POST['aantal'] + $_POST['begin'];
$ietsanders = $iets - 1;
$values = "'$_POST[a" . $_POST['begin'] . "]', " ;

for ($i = $_POST['begin'] + 1 ; $i < $ietsanders ; $i++){
    $values = $values . "'$_POST[a" .$i. "]', ";
}
$values = $values."'$_POST[a" . $ietsanders . "]', ";
echo "using  ".$values;
?>

This is my code; what’s wrong? It gives me an error at:

$values = $values . "'$_POST[a" .$i. "]', ";

and:

$values = $values."'$_POST[a" . $ietsanders . "]', ";

It gives me no error when I leave away the ' at '$_POST. I want my for loop to give me '$_POST[a$i]' every run:

'$_POST[a10]', '$_POST[a11]', '$_POST[a12]', '$_POST[a13]', 
  • 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-15T21:35:36+00:00Added an answer on June 15, 2026 at 9:35 pm

    Concatenate the string 'a' with $_POST['begin'] as in index to the outer $_POST, as in:

    $_POST['a' . $_POST['begin']]
    

    Your loop looks then like:

    // Concatenate a single quote with the $_POST dynamic key, then another single quote and comma.
    $values = "'" . $_POST['a' . $_POST['begin']] ."', " ;
    
    // In the loop, same thing concatenating single quotes around the $_POST key
    // dynamically built with $i
    for ($i = $_POST['begin'] + 1 ; $i < $ietsanders ; $i++){
        $values = $values . "'" . $_POST['a' .$i] . "', ";
    }
    

    The way you were attempting to do it by building up the $_POST['stuff'] as strings, would require a call to eval(), which is not to be done under most any circumstances when accepting user input like $_POST.

    If you are intending to pass these values from $_POST to a SQL query, you will need to be performing some protection against SQL injection on them. If possible, it is recommended to switch to an API supporting prepared statements instead.

    Finally, Not sure why you are writing to the $_POST superglobal. Hopefully you have a good reason to do this:

    $_POST['aantal'] = 4;
    $_POST['begin'] = 10;
    

    Update after comments:

    Well, it turns out the idea is to build the literal string '$_POST[a10]', '$_POST[a11]', '$_POST[a12]', '$_POST[a13]', rather than to interpolate the values from it. To do that, the string should be single-quoted to prevent the $ from delimiting variables.

    // Single quote the string, and escape single quotes inside it
    $values = '\'$_POST[a' . $_POST['begin'] . ']\', ';
    
    // In the loop, same thing concatenating single quotes around the $_POST key
    // dynamically built with $i
    for ($i = $_POST['begin'] + 1 ; $i < $ietsanders ; $i++){
        $values = $values . '\'$_POST[a' . $i .']\', ';
    }
    
    // After the loop, you have an extra comma and space at the end. trim() it off
    $values = trim($values, ', ');
    

    Here’s a working example

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

Sidebar

Related Questions

I want to use this function: http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html Its used to post to Wordpress using
This is my php where I need to authenticate: <?php $username=$_POST[m_username]; $password=$_POST[m_password]; /* $username=$_GET[m_username];
I am using the php post request example given on http://code.google.com/apis/chart/docs/post_requests.html for generating chart.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
This code in the first loop: <?php $terms_as_text = get_the_term_list( $post->ID, 'produktkategori', '', ',
I'm trying to make this: 174,myfilename.jpg Into this on the php post process page:
I write two file main.php and download.php . main.php echo<form action='download.php' method='post'> for(i =
I have this HTML: <form action='uploadhandle.php' method='POST' enctype=multipart/form-data> <input type='file' class='fileinput' id='photo1' name='photo1'> <input
I am using PHP http_post_data() call to send data to a cakephp controller.I do
Possible Duplicate: php $_POST array empty upon form submission I am trying to have

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.