Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Function AddUser

Posted on 2014-12-12
3
Medium Priority
?
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 59

Expert Comment

by:HainKurt
ID: 40496591
try comment out some lines

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

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

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 40496601
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
ID: 40529480
Thank you, forgot about procedures (told you it was a while...)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

721 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