0

I don't understand why I can't update one column. I have query

$db->setQuery("update #__cars set pro_cars='$itatit' where id='$id'");

It updates fine. If I want to update another column (pro_cars_it) in the same table it doesn't work.

$db->setQuery("update #__cars set pro_cars_it='$itatit' where id='$id'");

I don't have idea why is that. I tried to do both columns at the same time and it's only one table pro_cars updated in the same query.

$db->setQuery("update #__cars set pro_cars='$engtit', pro_cars_it='$itatit' where id='$id'");

Strange. Any idea?

Qirel
  • 25,449
  • 7
  • 45
  • 62
Tester
  • 1
  • 2
  • 1
    Is `#__cars` your actual table name? – John Conde Sep 11 '15 at 18:52
  • provide table structure of #__Cars... also is pro_cars_it varchar or numeric? – xQbert Sep 11 '15 at 18:53
  • I already checked. Both are the same (pro_name varchar(255) utf8_general_ci Yes NULL) – Tester Sep 11 '15 at 18:55
  • Run the query directly on mysql server with the php variable values only and see what happens – Gabriel Rodriguez Sep 11 '15 at 18:57
  • Yes, #__cars is the table name. – Tester Sep 11 '15 at 18:57
  • You need to escape the table name in that case. Use back-ticks. You should also consider only using alphanumerical characters, and underscores in your table/column names. https://dev.mysql.com/doc/refman/5.0/en/identifiers.html `Permitted characters in unquoted identifiers: ASCII: [0-9,a-z,A-Z$_] (basic Latin letters, digits 0-9, dollar, underscore)` – chris85 Sep 11 '15 at 18:58
  • It works directly on mysql server. Unbelievable. – Tester Sep 11 '15 at 19:02
  • possible duplicate of [When to use single quotes, double quotes, and backticks?](http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks) – chris85 Sep 11 '15 at 19:03
  • Depending on how those variables are set you also might be open to SQL injections. You should look into prepared statements. – chris85 Sep 11 '15 at 19:05
  • Are you sure you're using MySQL? In SQL-Server, table names beginning with `#` are temporary tables. – Barmar Sep 11 '15 at 19:18

0 Answers0