Error 1318: Incorrect number of arguments for PROCEDURE ComicHub.sp_createUser; expected 3, got 4

I keep Error 1318 when you run this code, I should have 4 of the argument: username, email, passwordand location. He raises 4, but thinks that he needs only 3 arguments. The code for the database and Python is below.

Python:

@app.route('/userSignUp',methods = ['POST'])
def userSignUp():
    try:
        #read values from signup form
        _username = request.form['username']
        _email = request.form['email']
        _password = request.form['password']
        _location = request.form['location']

        #validate recieved values
        if _username and _email and _password and _location:

            cur = mysql.connection.cursor()
            _hashed_password = generate_password_hash(_password)

            cur.callproc('sp_createUser', (_username, _email, _hashed_password, _location))

            data = cur.fetchall()
            cur.close()
            if len(data) is 0:
                mysql.connection.commit()
                return json.dumps({'success':'User created successfully!'})
            else:
                return json.dumps({'error':str(data[0])})
        else:
            return json.dumps({'html':'<span>Enter the required fields</span>'})

    except Exception as e:
        return json.dumps({'error':str(e)})

SQL:

# Create Database for ComicHub
CREATE DATABASE ComicHub;

# Create Table 'users' for ComicHub
CREATE TABLE `ComicHub`.`tbl_user` (
    `user_id` BIGINT NULL AUTO_INCREMENT,
    `user_username` VARCHAR(45) NULL,
    `user_email` VARCHAR(45) NULL,
    `user_password` VARCHAR(45) NULL,
    `user_location` VARCHAR(66) NULL,
    PRIMARY KEY (`user_id`)
);

# PROCEDURE for creating users from passed in data
USE `ComicHub`;
DELIMITER $$
CREATE PROCEDURE `sp_createUser` (
    IN p_username VARCHAR(20),
    IN p_email VARCHAR(20),
    IN p_password VARCHAR(20),
    IN P_location VARCHAR(20)
)
BEGIN
#check if user already exists
    IF (select exists (select 1 from tbl_user where user_username = p_username) ) THEN

        select 'Username Already Exists!';

    ELSE

        insert into tbl_user
        (
            user_username,
            user_email,
            user_password,
            user_location
        )
        values 
        (
            p_username,
            p_email,
            p_password,
            p_location
        );

    END IF;
END$$
DELIMITER ;
+4
source share
1 answer

Nevermind, fixed now, I realized that I did not update the database in MySQL Workbench. Stupid I know, but it was a long day!

0
source

All Articles