i am gettig this error in my expo app where i am trying to post data from reactnative app to mysql database.Its working well while using postman,But while sending data from my expo app its showing erro like this: ERROR Error logging in: [AxiosError: Request failed with status code 404]
const handleRegistration = async () => {
const userData = {
firstName: firstName,
lastName: lastName,
phoneNumber: phoneNumber,
email: email,
password: password,
occupation: occupation,
selectedState: selectedState
};
try {
const response = await axios.post('http://192.168.200.226:3000/register', userData);
if (response.status === 200) {
console.log('Data sent to server:', response.data);
navigation.navigate('Login');
} else {
alert('Error inserting data. Please try again later.');
}
catch (error) {
console.error('Error sending data to server:', error);
}
}
—
app.post('/register', (req, res) => {
const { firstName, lastName, phoneNumber, email, password, occupation, selectedState } = req.body;
// Check if user with same email or phone number already exists
const checkQuery = 'SELECT * FROM users WHERE email = ? OR phoneNumber = ?';
db.query(checkQuery, [email, phoneNumber], (err, result) => {
if (err) {
console.error('Error checking user data:', err);
res.status(500).send('Error checking user data');
} else {
if (result.length > 0) {
const existingUser = result[0];
if (existingUser.email === email) {
res.status(409).send('Email already exists');
} else if (existingUser.phoneNumber === phoneNumber) {
res.status(409).send('Phone number already exists');
}
} else {
// No existing user with same email or phone number, proceed with registration
const insertQuery = 'INSERT INTO users (firstName, lastName, phoneNumber, email, password, occupation, selectedState) VALUES (?, ?, ?, ?, ?, ?, ?)';
db.query(insertQuery, [firstName, lastName, phoneNumber, email, password, occupation, selectedState], (err, result) => {
if (err) {
console.error('Error inserting data:', err);
res.status(500).send('Error inserting data');
} else {
console.log('Data inserted successfully');
res.status(200).send('Data inserted successfully');
}
});
}
}
});
});
const port = 3000;
const ipAddress = '192.168.200.226';
app.listen(port, ipAddress, () => {
console.log(`Server is listening on http://${ipAddress}:${port}`);
});
with postman : enter image description here
from UI:enter image description here
how to solve this issue, how can i send data from the UI to Db`