简体   繁体   中英

Using one Array Value As Another Array Key PHP MySQL

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']]')";

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']]}')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM