Make sure email is stored as a string [Raku]

122 views Asked by At

Not sure how to close this, but I can no longer delete it either... The issue is resolved

I have a form where users input an email and CRO tries to query the email in an accounts database to find a match. The problem is that Sqlite3 sees the @ symbol as an operator and gives an error. It works if I declare it as a string, but how do I do that inside Routes.pm6? Here is the block of code I'm working on.

post -> 'reset' {
        request-body -> (:$email) {
        #Check to see if email exists in accounts
        #If Exists then send email
        #If not exists post email not found

                $sth = $dbh.prepare(q:to/STATEMENT/);
                select email from accounts WHERE email = (?) 
                    STATEMENT

        # $email = $email.Str
        my $results = $sth.execute("$email");

        if $results == 1 {
            content 'text/html','Successful Email sent' ~ '<br><a href="/">Home</a>';
        } else {
            content 'text/html', "Email does not exist";
        }
        }
    }

I have tried various things like adding Str in request body or .Str in random places. I have also tried adding quotes. This is the html file:

<DOCTYPE html>
<html lang="en">
<head>
    <title>Reset Password</title>
</head>
<body>
    <form action="/reset" method="post">
      Email:<br>
      <input type="text" name="email">
      <br>
      <input type="submit" value="Submit">
      </form>
      <br>
      <a href="register.html">Create an Account</a>
      <a href="signin.html">Sign In</a>
      <br>
      <a href="/">Home</a>
</body>
</html>

What I'm trying to say is: How do I make sure that whatever the user inputs is a string and then is queried as a string in sqlite3?

0

There are 0 answers