Skip to content
Advertisement

PHP, SQL – INSERT INTO SELECET CASE

I have this PHP code connected with form (using nette framework), name of columns are different in every table but geo column is in everyone:

which generate this SQL:

but I’m getting this error:

The goal is to COPY data into the same table but change value of geo column before insert. I know that ELSE value looks stupid but CASE will always end up same because the WHERE selection.

How can I fix this error or should I use different approach? Thanks.

Advertisement

Answer

The syntax error is because you’re missing a comma before CASE. But there are other problems with the query after fixing that.

You don’t need the CASE expression at all, since the WHERE clause is only selecting those rows. What you want is:

To do this with your variables, you’ll need to remove geo from $cols so that SELECT ".$cols will not include it and you can add $values["new_text"] at the end of the SELECT list.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement