0
type here
function registerfuncion(username,password,fullname,DOB){
    let rusername =username;
    let rfullname=fullname;
    let rpassword=password;
    let rDOB=DOB; 
    var regmessage="";
    var reg_status=false;
    var reg={};
        if(!rusername || !rpassword ||!rfullname ||!rDOB){
            regmessage="fill all the fields";
            reg_status=false;
        }else(client.query(`SELECT username FROM user_details WHERE username='${rusername}'`,(err,res)=>{
            if(res.rowCount==0){
                client.query(`INSERT INTO user_details(username,fullname,dob) VALUES('${rusername}','${rfullname}',current_date);`,(err,res)=>{
                    if(!err){
                        client.query(`SELECT * FROM user_details WHERE username='${rusername}';`,(err,res)=>{
                            if(!err){
                                client.query(`INSERT INTO user_cred(userid,password,last_login) VALUES(${res.rows[0].userid},'${rpassword}',current_date);`,(err,res)=>{
                                    if(!err){
                                        reg_status=true;
                                        regmessage="register successful";
                                        // console.log("dsf");
                                    }else{
                                        console.log(err.message);
                                    }
                                });
                            }else{
                                console.log(err.message);
                            }
                        });
                    }else{
                        console.log(err.message);
                    }
                });
            }else{
                regmessage="username already taken";
                reg_status=false;
            }
setTimeout(function(){
             reg={regmessage,reg_status};
             console.log(reg);
        },200);
    return reg;

i want to return the variable with the changed value variable reg which is changed while the function is exicuted.the regmessage and red_status are suppose to change but the initial {} is returned to the function while it is called

0 Answers0