Php kod mysql hatası

5 Cevap php

mysql hatası anlayamıyorum:

UPDATE static_pages SET order = " Some new data 222222

"Database error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order = "

$query = 'UPDATE someTable SET '.$key.' = "'.$value.'"';

Here is $key = order; $value = 'new data 222222'; There is such keys in table: order, prices, contacts. Each of these updates well except the 'order'. Why?

5 Cevap

ORDER ayrılmış bir sözcüktür.

Kullanım geri sütun adını kaçmak için keneler:

UPDATE static_pages SET `order` = ";

Eğer sadece belirli kayıtları güncellemek böylece WHERE yan tümcesi unutma.

UPDATE static_pages SET `order` = "
WHERE id = 12;

sipariş SQL bir anahtar kelimedir. Sorgunuzda tırnak korumak.

En iyi seçenek, 'sipariş' alanını yeniden adlandırmak için

Eğer yapamıyorsanız, burada olası bir çözüm:

$query = 'UPDATE someTable SET `'.$key.'` = "'.$value.'"';

Nerede WHERE

Güncelleme dostum ile WHERE yan tümcesi kullanmak zorunda

`tuşunun çevresinde kullanmak

$query = "UPDATE `someTable` SET `$key` = '$value'";

Sen '`' ters tırnakların içine reserved word orders kapamak veya alanı yeniden adlandırabilirsiniz.