Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Function AddUser

Long time since Ive done any functions in MySQL and Im a bit stuck.

From memory Ive got the following:-
DROP FUNCTION IF EXISTS AddUser
DELIMITER $$
CREATE FUNCTION AddUser(username VARCHAR(255, password VARCHAR(255))
BEGIN
	INSERT INTO `users` (`username`, `password`) VALUES (username, AES_ENCRYPT(password,'cryptstring')); 
END;
$$
DELIMITER ;

Open in new window


I thought the issue was with the parameters, however the error is:-
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO `users` (`username`, `password`) VALUES (username, AES_ENCRYPT(passw' at line 3

Any ideas, what Im doing wrong?
0
tonelm54
Asked:
tonelm54
  • 2
1 Solution
 
HainKurtSr. System AnalystCommented:
try comment out some lines

delete/comment out line 2,7,8 and try again...

find where the problem is first...
0
 
HainKurtSr. System AnalystCommented:
the other thing is this does not look like a function but procedure

CREATE PROCEDURE AddUser(username VARCHAR(255, password VARCHAR(255))
BEGIN
	INSERT INTO `users` (`username`, `password`) VALUES (username, AES_ENCRYPT(password,'cryptstring')); 
END;

Open in new window


if it is really a function, where is the return clause?

check MySQL Reference
0
 
tonelm54Author Commented:
Thank you, forgot about procedures (told you it was a while...)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now