0

I'm making login function this alert shows up twice

else{ alert("wrong pw"); }

I tried this but didn't work.

  break;
  continue;

here I try connect to db and get vaule of input

JS

function loginConfirm2() {

  var id = $('#id').val();
  var s_id = "'" + id + "'";
  var pw = $('#password').val();
  var pw = '' + pw;
  var alert_id=null;
  var alert_pw=null;

  console.log(id);
  console.log(pw);
  if(id==''){
    alert_id="enter id"
    alert(alert_id);
  }else if (pw=='') {
    alert_pw="enter pw";
      alert(alert_pw);
  }
  if (id) {
    db = new sqlite3.Database('mydb.db');
    db.each("SELECT id, pw FROM user where id=" + s_id, function(err, row) {
      console.log("db에 저장된 id는" + row.id);
      if ((id == row.id) && (pw == row.pw)) {
        window.location.href = "distribute_download.html?id=" + id;
      }
      else{
        alert("wrong pw"); 
      }
    });

alert("wrong id"); return;
    db.close();
  }
}
hoho
  • 25
  • 6

1 Answers1

0

The else is inside a each loop which might yield multiple results which may lead to multiple alerts

varoons
  • 3,807
  • 1
  • 16
  • 20