What’s wrong with my Mysql code?

Asked

Viewed 60 times

1

The error is this: error code 1064. You have a error in your sql syntax;

This is my code:

INSERT INTO pessoa (Endereço, Email, Telefone)
VALUES ('Rua Ernesta de Oliveira Pina', '[email protected]',
'(62) 1234-5678') WHERE PS_NOME='Átila o Encapuzado'

1 answer

7

When you use INSERT in Mysql you cannot use the WHERE clause, nor need it, because WHERE is for selecting results, and INSERT does not mess with results, it just creates a new row (or tuple) in the table.

Your code would be:

Insert into pessoa (Endereço, Email, Telefone) values ('Rua Ernesta de Oliveira Pina', '[email protected]', '(62) 1234-5678') 

Source: https://stackoverflow.com/a/485062/3473971

EDIT

If Voce wants to enter this data in the given line, actually Voce is doing an UPDATE, and not an INSERT.

UPDATE pessoa SET (Endereço='xxxx', Email='ccccc', Telefone='21312321') WHERE nome='Atila blablal'

Something in these lines, therefore you need to adapt to what you need.

Source in SQL UPDATE: http://www.w3schools.com/sql/sql_update.asp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.