C
C
cth abuk2020-08-20 16:53:31
PHP
cth abuk, 2020-08-20 16:53:31

sql query not running in php, how to fix error?

There is a sql query in php:

$sql 'UPDATE `_spi`
SET `w_st`=`w_t`+`w_s`+`w_z`+`w_p`
CASE WHEN `p_m` =  'IV'
THEN `w_t`+`w_s`
ELSE 0
END';

But when I run it I get an error:
PHP Parse error: syntax error, unexpected 'IV' (T_STRING)

I just don't know what's wrong? Tell me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2020-08-20
@abb72

$sql = "UPDATE `_spi`
SET `w_st`=`w_t`+`w_s`+`w_z`+`w_p`
CASE WHEN `p_m` =  'IV'
THEN `w_t`+`w_s`
ELSE 0
END";

I
idShura, 2020-08-20
@idShura

The quotes need to be escaped.
And it looks like the sign (+ etc.) forgot to put before CASE

$sql 'UPDATE `_spi`
SET `w_st`=`w_t`+`w_s`+`w_z`+`w_p` + CASE WHEN `p_m` =  \'IV\' THEN `w_t`+`w_s` ELSE 0 END';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question