Syntax error in MySQL procedure while using if else insert query

I am trying to create a stored procedure with MySQL but I kept receiving the error prompt but i cant find the error in my query.

I’m coming from MS SQL background and I’m not sure how is my query wrong. Anyone understands the error?

Error Code: 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 '' at line 11

CREATE PROCEDURE SP_AddUpdateUser
(
    IN InputUsername VARCHAR(512),
    IN InputPassword VARCHAR(512),
    IN InputEmail VARCHAR(512)
)
BEGIN

    if(NOT EXISTS(SELECT 1 FROM TB_User WHERE Username = InputUsername)) then
            INSERT INTO TB_User(Username, Password, Email, DateCreated)
            SELECT InputUsername, InputPassword, InputEmail, Now();
    else
            UPDATE TB_User SET Password = InputPassword, Email = InputEmail WHERE Username = InputUsername;        
    end if;
END;;

Answer

You are taking the wrong approach in MySQL. It has a single statement that supports “upserts” — and insert with on duplicate key update.

This is triggered when you have a unique index or constraint on the column that cannot be duplicated. In this case, username.

Start with a unique constraint or index:

create unique index unq_tb_user_username on TB_User(username);

You may already have this. Then, the body of the procedure would simply be:

CREATE PROCEDURE SP_AddUpdateUser
(
    IN InputUsername VARCHAR(512),
    IN InputPassword VARCHAR(512),
    IN InputEmail VARCHAR(512)
)
BEGIN
    INSERT INTO TB_User(Username, Password, Email, DateCreated)
        SELECT InputUsername, InputPassword, InputEmail, Now()
        ON DUPLICATE KEY UPDATE Password = InputPassword, Email = InputEmail;
END;

Here is a db<>fiddle.