Why does this SQL statement produce the error statement further below ?
INSERT INTO members ('','Prep','[email protected]',password,salt)
SELECT password, salt
FROM member
where id=3
Error statement
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''','Prep','[email protected]',password,salt) SELECT * FROM member where ...' at line 1
CodePudding user response:
I think you want something like this
INSERT INTO members (`name`, `email`,`password`,`salt`)
SELECT 'Prep','[email protected]', password, salt FROM member where id=3
BIG Note Dont salt your own password hash, use password_hash()
it does a better job on its own than you are likely to do and then password_verify()
CodePudding user response:
Because when you use insert statement and select like this, MySql except you to provide a complete row to insert from the select.
To insert only one line but using a column from a select, you will likely use something like this :
INSERT INTO members ('',
'Prep',
'[email protected]',
SELECT password FROM member where id=3
SELECT salt FROM member where id=3
)