0

This is my code which I call to issue a post request (everything from the docs). I'm using Axios in React with Redux.

  export function postRequest(url) {
    axios.post(url, {
      param_0:1,
      param_1:22
     })
      .then(response => {
        console.log(response);

     })
      .catch((err)=>{
        console.log("Error on issuing post request");

     })
  }

Calling my function

databaseCall.postRequest('http://myurl.com/input.php');

It gets to my PHP script (runs SQL insert statement) and runs successfully apart from my _POST params being null. My params somehow don't get to the server.

I get the response from .then but params aren't there therefore my SQL INSERT fails.

What could be wrong here?

I don't gen any errors on the frontend just index undefined for _POST params on the backend.

Here is the requested PHP code:

$stmt = $conn->prepare("INSERT INTO basic_person 
(id, age, weight, weight_si, height, height_si, gender, race) 
VALUES (?, ?, ?, ?, ?, ?, ?, ?)");

$stmt->bind_param("iiisisss", $id, $age, $weight, $weight_si, $height, $height_si, $gender, $race);
if (isset($_POST["param_0"])) {
    echo "SET!";
} else {
    echo "it is not set";
}
$id        = $_POST['param_0'];
$age       = $_POST['param_1'];
$weight    = $_POST['param_2'];
$weight_si = $_POST['param_3'];
$height    = $_POST['param_4'];
$height_si = $_POST['param_5'];
$gender    = $_POST['param_6'];
$race      = $_POST['param_7'];

$stmt->execute();

Note: My get request with params works without any problem

EugenSunic
  • 13,162
  • 13
  • 64
  • 86

0 Answers0