Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I am getting a syntax error:

unexpected ']'

Here is my code:

<?php

$output = "";
for ($i=1; $i<16; $i++) {
    $output .= $_POST["DepositCode" . i . ] . "," . $_POST["textfield" . i . ] . "," . $_POST["AccountNum" . i . ] . " \r\n"; 
    }

$file ='textt.txt';
file_put_contents($file, $output);
?>
share|improve this question

closed as too localized by hakre, PeeHaa, tereško, Jocelyn, Vikdor Oct 21 '12 at 0:35

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Should be $_POST["DepositCode" . i] - remove the last dot (.) – hafichuk Nov 28 '11 at 16:41
    
also should be $i not i. thanks everyone – JDV590 Nov 28 '11 at 16:52

4 Answers 4

$output .= $_POST["DepositCode" . i . ] . "," etc...
                                    ^--- extra concat operator

as well as two other places later in the same line. i by itself is invalid as well. it should be $i. The whole line could be replaced with:

$output .= $_POST["DepositCode$i"] . "," . $_POST["textfield$i"] . "," . $_POST["AccountNum$i"] . " \r\n"; 

instead.

share|improve this answer

This line is wrong:

$output .= $_POST["DepositCode" . i . ] . "," . $_POST["textfield" . i . ] . "," . $_POST["AccountNum" . i . ] . " \r\n";

The right code is:

$output .= $_POST["DepositCode" . $i] . "," . $_POST["textfield" . $i] . "," . $_POST["AccountNum" . $i] . " \r\n";
share|improve this answer
$_POST["X" . i . ] >> $_POST["X" . i]
share|improve this answer
    
Wrong, it's $i not i. – Dimme Nov 28 '11 at 16:45

Check your 'i'-s in the for-loop. They are all missing the '$'-sign.

Edit: And check the other posts concerning the concatination.

share|improve this answer
    
And en extra dot before the ] – Dimme Nov 28 '11 at 16:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.