When returning a template to render with a message, ejs wont add it to html

I’m unsure how to word the title please edit it as necessary.
The problem I’m having is than in my server code a database query is made to determine if the account name is a dupe, if it is a message is returned with the template:

con.query('SELECT * FROM Users WHERE username = ?', [username], async (err, results) => {
        if (err) {
            return res.render("register.ejs", {
                message: "Error"
            })
        }
        if (results.length > 0) {
            return res.render("register.ejs", {
                message: "Username taken"
           })
        }
})

This message is then meant to be "added" to the html in my ejs file so the user can see it is taken. I can’t seem to get this to work. Ejs file:

 <% if (message) { %>
     <h3><%= message %></h3>
 <% } %>

Also, the code itself does work as the website won’t let me add a duplicate user, the message just won’t show.

97 thoughts on “When returning a template to render with a message, ejs wont add it to html”

Leave a Comment