Solved

Function AddUser

Posted on 2014-12-12
3
123 Views
Last Modified: 2015-01-03
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
Comment
Question by:tonelm54
  • 2
3 Comments
 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
try comment out some lines

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

find where the problem is first...
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:tonelm54
Comment Utility
Thank you, forgot about procedures (told you it was a while...)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now