1

I want to use a value from one array as the key for another as part of a MySQL replace statement. I tried the code below but got a syntax error of

"Unexpected '[' expected ']'"

Can this be done and if so any help with the right syntax would bemuch appreciated.

$sql = "REPLACE INTO sections(IDENTIFIER, NAME, DESCRIPTION, SEQUENCE, INSTRUCTIONS, TIME_AVAILABLE, EXTERNAL_RESOURCE)
            VALUES ('$currentline[$flippedheaders['IDENTIFIER']]', '$currentline[flippedheaders['NAME']]', '$currentline[flippedheaders['DESCRIPTION']]', $currentline[flippedheaders['SEQUENCE']], '$currentline[flippedheaders['INSTRUCTION']]', $currentline[flippedheaders['TIME_AVAILABLE']], '$currentline[flippedheaders['EXTERNAL_RESOURCE']]')";
1

1 Answer 1

1

I see you have a lot of typos there, mising quotes and not properly interpolating the string. Try as follows:

$sql = "REPLACE INTO sections(IDENTIFIER, NAME, DESCRIPTION, SEQUENCE, INSTRUCTIONS, TIME_AVAILABLE, EXTERNAL_RESOURCE)
        VALUES ('{$currentline[$flippedheaders['IDENTIFIER']]}', '{$currentline[$flippedheaders['NAME']]}', '{$currentline[$flippedheaders['DESCRIPTION']]}', '{$currentline[$flippedheaders['SEQUENCE']]}, '{$currentline[$flippedheaders['INSTRUCTION']]}', '{$currentline[$flippedheaders['TIME_AVAILABLE']]}', '{$currentline[$flippedheaders['EXTERNAL_RESOURCE']]}')";
Sign up to request clarification or add additional context in comments.

1 Comment

Aside from the embarrassing typos, not interpolating the string was the main issue here. I knew that's what I needed to do but not what it was called or how to do it so this was a huge help, thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.