0

I am trying to do a MySQL Update where the code updates the database if both FACTORY_ID is 175 and SQUAD is PRODUCTION_SQUAD. The code works fine when just checking the FACTORY_ID but then doesn't work when I add the AND. I have tried encasing the 'SQUAD'='PRODUCTION_SQUAD' in brackets as this is what a lot of examples are telling me to do and it is still not working.

mysql_query("UPDATE Drug_Factory_Thugs SET `HEALTH`='10' WHERE `FACTORY_ID`='175' AND 'SQUAD'='PRODUCTION_SQUAD'")
           or die("factory set data connect to database failled!");
Ankur Tiwari
  • 2,762
  • 2
  • 23
  • 40
  • 2
    Possible duplicate of [When to use single quotes, double quotes, and back ticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-back-ticks-in-mysql) – Nick Feb 26 '19 at 11:45
  • Obligatory comment about `mysql_` being outdated, removed in PHP7 and insecure. – Qirel Feb 26 '19 at 11:47

2 Answers2

1

If you put your column in ' ' Sql suppose there is a string in it . It doesn't act like a columns. So you need to change 'SQUAD' with ``

mysql_query("UPDATE Drug_Factory_Thugs SET `HEALTH`='10' WHERE `FACTORY_ID`='175' AND `SQUAD`='PRODUCTION_SQUAD'")
Omer Tekbiyik
  • 4,255
  • 1
  • 15
  • 27
0

Try below codes:

mysqli_query("UPDATE Drug_Factory_Thugs SET `HEALTH`='10' WHERE `FACTORY_ID`='175' AND `SQUAD`='PRODUCTION_SQUAD'")
           or die("factory set data connect to database failled!");

Or

mysqli_query("UPDATE Drug_Factory_Thugs SET `HEALTH`=10 WHERE `FACTORY_ID`=175 AND `SQUAD`='PRODUCTION_SQUAD'")
           or die("factory set data connect to database failled!");

Hope it will work for you.

  • 2
    can you explain how this code answers the question, or at least point out how it differs from the code in the question? – tshimkus Feb 26 '19 at 11:42
  • 2
    And why did you suddenly change API? I get that `mysql_` is outdated, but you can't just add an `i` and expect it to work – Qirel Feb 26 '19 at 11:46