skip to Main Content

Im making node.js / express app and I want to use uuid to generate token.
the token contains the dash. When im trying to Select column where token is like fdda765f-fc57-5604-a269-52a7df8164e it doesnt work but when the token is like fdda765ffc575604a26952a7df8164e it does work. In addition i tried to type SQL query in PHPmyadmin panel and it returned my column where token was with dashes? Im using this module const mysql = require(‘mysql’);

Also i found out when i pass value directly into query like this:

"SELECT CONFIRM FROM ORDERS WHERE TOKEN = 'd63d2-5a15-11ea-ae4d-79a508'"

and not with ? it also works.

here is my code

exports.getConfirmation= function(token) {
    return new Promise((resolve, reject) => {
    var sql = "SELECT CONFIRM FROM ORDERS WHERE TOKEN = ?";
    con.query(sql, [token], function (err, rows) {
        if (err) {
            return reject(err);
        } else {
            return resolve(JSON.parse(JSON.stringify(rows)));
        }
    });
  })
}

Any ideas how can I solve this issue ?

2

Answers


  1. Chosen as BEST ANSWER

    Maybe this snippet helps to debug my code. I actually getting the token from req.params. Maybe it parses it in a wrong way

    let tok = req.params.generatedToken;
    db.getConfirmation(tok)
                .then((data) => {
                    let confirmation = data[0].CONFIRM;
    

    Im getting this TypeError: Cannot read property 'CONFIRM' of undefined


  2. Try replacing

    var sql = "SELECT CONFIRM FROM ORDERS WHERE TOKEN = ?";
    

    with

    var sql = "SELECT CONFIRM FROM ORDERS WHERE TOKEN = '?'";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search