简体   繁体   中英

MySQL field name conflict

I have this table with 50 something fields each field contains the corresponding two character state name. I have this mysql_query when a state is selected

//$entry is state name abbr. Oregon = OR<br/>
//$cname and $zoneName aren't important.

'UPDATE stateCarriers SET '.$entry.'= 1 WHERE cname="'.$cname.'" AND zone="'.$zoneName.'"'

so I'm having an issue when OR is the $entry since mysql thinks it is the OR operator.

How do I solve this issue without changing the field name to something else?

Try using the backtick character, eg `field`=1 to delimit the field. This seems to work pretty well for me, although it was under slightly different circumstances.

'UPDATE stateCarriers SET`'。$ entry.'` = 1 WHERE cname =“'。$ cname。'”AND zone =“'。$ zoneName。'”'

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