5

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?

3leggedquid
  • 67
  • 1
  • 4
  • I'm dumb. Forgot to add .allrows to $sth. – 3leggedquid Mar 06 '20 at 01:32
  • 1
    I voted to close this question because I hoped to avoid folk wasting time trying to process it unless the OP confirms they still want it answered; the wording is highly ambiguous (can *you* be confident you know what OP means?); the example is explicitly and clearly not remotely close to an [MRE]; the issue *seems* to be trivial; it looks like the OP answered their question -- they "Forgot to add .allrows to $sth" (but they didn't clarify, or make that an answer, or update their question to include .allrows), and OP hasn't returned since. – raiph Mar 08 '20 at 11:43

0 Answers0