I'm working on a project that uses expressjs, Php, Html and MongoDB
I have this code in my "Index.Html" File
<form action="/Login" method="POST">
<input type="text" placeholder="name" name="Username">
<input type="Password" placeholder="Password" name="Password">
<button type="submit">Submit</button>
</form>
I have this code in my "Server.js" File (Expressjs)
app.post('/Login', (req, res) => {
//to know that I really had recieve a data from my index.html
console.log(req.body)
//to collect data from my database (MongoDB)
db.collection('User').find(req.body,{Username:"",password:""}).toArray(function(err, results) {
//show result from the database
console.log(results)
//The Question Starts here.
})
})
How can I send both of those data (req.body and result) to my php file? so I can Validate it. and also how can I send the data back from the PhP back to the server so the server could send the data back to the client?
You can use fetch
to post a request to a php server. Example from the docs:
fetch('flowers.jpg')
.then(function(response) {
return response.blob();
})
.then(function(myBlob) {
var objectURL = URL.createObjectURL(myBlob);
myImage.src = objectURL;
});