Question: Having trouble with this. I want to reference the post superglobal using a key which is generated by the concatenation of a string literal and a string variable.

```
$guests = array();
$guest_data = $this->compile_guests_for_hcp('g1');
array_push($guests, $guest_data($hcp_id));

function compile_guests_for_hcp($guest_identfier){
    return function($hcp_id) use ($guest_identfier){
        $guest = array(
            'fname' => $_POST["fname_$guest_identifier"],
            'lname' => $_POST["lname_$guest_identifier"],
            'city' => $_POST["city_$guest_identifier"],
            'state' => $_POST["state_$guest_identifier"],
            'degree' => $_POST["degree_$guest_identifier"],
            'zip' => $_POST["zip_$guest_identifier"],
            'specialty' => $_POST["specialty_$guest_identifier"],
            'email' => $_POST["email_$guest_identifier"],
            'phone' => $_POST["pref_phone_$guest_identifier"],
            'job_title' => $_POST["job_title_$guest_identifier"],
            'office_addr_line_1' => $_POST["office_addr_line_1_$guest_identifier"],
            'office_addr_line_2' => $_POST["office_addr_line_2_$guest_identifier"],
            'hcp_data_idhcp_data' => $hcp_id
        );
        return $guest;
    };
}

```

PHP is throwing undefined variable errors as it's trying to reference for example `$_POST["fname_"]` and `$_POST["guest_identifier"]`

I'm trying to access $\_POST["fname\_g1"] etc.

Answer: 
Second to testing if the variable is set using `isset()` before you try to access its value. You can even be more direct in your syntax and write the string concatenation in:

```
$var = isset( $_POST[ 'fname_' . $guest_identifier]) ? 
           $_POST[ 'fname_' . $guest_identifier] : 'default_value'

```

Your post makes it sound like PHP is trying to access two separate variables, `$_POST["fname_"]` and $\_POST["$guest\_identifier"], which shouldn't be the case, especially with the above syntax.
This will help you in making dynamic insertion of `n` number of product.

```
$loopLength=$_POST['ProudctSize'];

for ($i=1; $i <=$loopLength; $i++) 
{
    $productid=$_POST['P'.$i];
    $quatity=$_POST['Q'.$i];
    $rate=$_POST['R'.$i];

   $Insert=mysql_query("INSERT INTO saledisplay ( `saleid`, `productid`, `quantity`, `rate`) 
                    VALUES('$oid','$productid','$quatity','$rate')");
}

```