UPDATE syntax?


#1

Hi, this is obviously a bug in phpmyadmin.

When i change:

UPDATE `arma_user1_xml` SET `squadNick` = 'Squad Nick 1' WHERE `id` =1 LIMIT 1 ;

to php code in phpmyadmin:

SQL-query: $sql = 'UPDATE `arma_user1_xml` SET `squadNick` = ''Squad Nick 1'' WHERE `id` = 1 LIMIT 1';

I get:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in C:xampplitehtdocsinsert.php on line 37

I tried fix this by adding “” instead of ‘’ from the start of UPDATE to the end of LIMIT 1:

SQL-query: $sql = "UPDATE `arma_user1_xml` SET `squadNick` = ''Squad Nick 1'' WHERE `id` = 1 LIMIT 1";

Errors goes away, but doesn’t update the database, is the syntax reading propaly?

Thanks v. much in advance


#2

SRY, after messing around like mad trying to fix it i got it right


#3

In php you don’t double the quotes (i.e. “” <- 2 double quotes) to escape them, you use a backslash.

so you had

[php]
SQL-query:
$sql = ‘UPDATE arma_user1_xml SET squadNick = ‘‘Squad Nick 1’’ WHERE id = 1 LIMIT 1’;
[/php]

when it should have been

[php]
SQL-query:
$sql = ‘UPDATE arma_user1_xml SET squadNick = ‘Squad Nick 1’ WHERE id = 1 LIMIT 1’;
[/php]

Also you don’t really need the back ticks [b]`[b] around the table and field names. I know phpMyadmin puts them in there, but it’s not required in normal php. I personally find the back ticks a bit confusing in my queries. Also you don’t need the LIMIT statement on the update. However it is a “Safety” mechanism that might prevent you from changing the entire database by forgetting a “WHERE” clause.

So given my above statement you could have written the query like this:
[php]
SQL-query:
$sql = ‘UPDATE arma_user1_xml SET squadNick = ‘Squad Nick 1’ WHERE id = 1’;
[/php]

Either way, I am glad you got it solved.