Home>

I would like to fetch the MySQL table information as shown below and sort the processing by pressing the button.
However, if there are two placeholders like updatesql, I don't know how to specify it on the node side.

const checksql= "SELECT * FROM users WHERE name=?";
const checkname= "SELECT status FROM users WHERE name=?";
const updatesql= "UPDATE users SET? WHERE?";
if (req.body.begin_button) {
    var name_checked= await query (checksql, {name: req.body.input_name});
    var status_checked= await query (checkname, {name: req.body.input_name});
if (name_checked== 0) {
      var results= await query (sql, {id: id, name: req.body.input_name, email: req.body.input_mail, start: now, status: 1});
    } else {
      console.log ("error");
    };;
  }
  else if (req.body.finish_button) {
    if (name_checked!= 0) {
      var results= await query (updatesql, {end: now, status: 0});
    } else {
      console.log ("error");
    }
  }
  else if (req.body.start_button) {
    if (status_checked== 1) {
      var results= await query (updatesql, {restbegin: now, status: 2});
    } else {
      console.log ("error");
    };;
  } else if (req.body.end_button) {
     if (status_checked== 2) {
        var results= await query (updatesql, {restend: now, status: 3});
     } else {
        console.log ("error");
     };;
  };;
  • Answer # 1
    UPDATE users SET xxx=?, xxx=? WHERE xxx=?
    
    It was solved by bringing it in each If statement as

    .
    Thank you very much.

  • Answer # 2
    UPDATE users SET xxx=?, xxx=? WHERE xxx=?
    
    It was solved by bringing it in each If statement as

    .
    Thank you very much.