I am not able to give post request using axios
in react
while i am giving post request to my php server and wanted to insert data in mysql fetched by post request.
this is my code.
const url = "http://localhost:80/react-backenda/";
const axios = require('axios');
axios.post(url, {
SendBy: 'username',
Sendto: 'got_name',
Msg: 'input'
})
.then(res=> console.log(res.data))
.catch(err => console.log(err));
i am getting this in my console:
Notice: Undefined index: Msg in C:\xampp\htdocs\react-backenda\index.php on line 10
Notice: Undefined index: Sendby in C:\xampp\htdocs\react-backenda\index.php on line 11
Notice: Undefined index: Sendto in C:\xampp\htdocs\react-backenda\index.php on line 12
done
this is my php script:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "msg-clone";
$conn = mysqli_connect($servername, $username, $password, $database);
if(!$conn){
die("could not connect to server!");
}
$recText = $_POST['Msg'];
$sendby = $_POST['Sendby'];
$sendto = $_POST['Sendto'];
echo $recText;
$sql = "INSERT INTO `messages` (`id`, `text`, `sendby`, `sendto`, `time`) VALUES (NULL, '$recText', '$sendby', '$sendto', current_timestamp());";
$res = mysqli_query($conn, $sql);
if ($res){
echo "done";
}else {
echo "err";
}
?>
help to solve this issue.