I'm using React front end with a PHP back end to communicate with database. I have a login.js page in which I'm sending the state values to a PHP file to communicate and process those logins. When I run the application It's giving me a 404 not found error for the PHP file.
Here is my Login.js
const API = "../../api/dbConnect.php";
<form>
.....
<button type="submit" name="submit" onClick={this.handleSignin}>Sign In</button>
</form>
And the handleSignin function,
handleSignin = (event) => {
event.preventDefault();
axios({
method:'POST',
url:`${API}`,
data:this.state,
headers: { 'content-type': 'application/json' },
})
.then(result => {
console.log(result)
})
.catch(error => console.log(error))
}
The API location is correct as per my folder structure,
root>
api/dbConnect.php
public/
src/components/Login.js
Error is as follows,
GET http://localhost:3000/base/api/dbConnect.php 404 (Not Found)
I'm using a basename as base in App.js as <Router basename="/base">.
localhost:3000. You'll need to serve it in a web server, such an Apache and then make requests to it through the web server. Currently you making requests to what seems like the react-app dev server./var/www/html/react. And I'm making a axios request to PHP page which is underreact/api/dbConnect.php. Can you please explain the mistake I'm doing?'/api/dbConnect.php'. And FWIW, `${API}` is the same as justAPI.http://localhost/react/api/dbConnect.php.