当我的sql查询必须通过表中的两个元素进行选择时,如何在rest api上的app.get函数中对路径进行正确设置



我是安卓应用程序开发的新手,我正试图使用rest api对我的应用程序进行身份验证,但我无法在我的函数"app.get"上找到正确的路径

app.get('/getPatient2/:id_patient/',function(req,res){ 
var query = "select * from Patient where id_patient = " + req.params.id_patient ; 
connection.query(query,function(error,results){
if (error) throw error;
res.send(results);
})
});

好吧,当我在浏览器上使用以下路径进行测试时:

http://localhost:8082/getPatient2/1

它正常显示结果,但这不是我在认证中需要的,它应该通过电话号码和密码,这意味着:

app.get('/xxxxx',function(req,res){ 
var query = "select * from Patient where phone_patient =" + req.params.tel + "and paasword=" + 
req.params.pass; 
connection.query(query,function(error,results){
if (error) throw error;
res.send(results);
})
});

我尝试了很多路径,但总是出现错误,我搜索了很多文档,但没有找到任何带有"and"的查询示例

我真的希望你能帮助我提前感谢

路径应该提供这两个参数,例如,其中任何一个都应该工作:

/get-patient/:tel/:pass
/get-patient/tel/:tel/pass/:pass

此外,您的SQL查询中有一个拼写错误:paasword

顺便说一句,考虑至少使用HTTPS通过网络传递密码,并使用DB连接库的参数化查询功能。此外,请确保在数据库中对密码进行散列。

最新更新