I am using react js for web front end and php for back end, on button click on web page i am trying to send data to server but getting this Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:84)
I have tried two different ways for sending data to server but with each i got the same error. can anyone help me out?
React Code:
axios({
      method: "post",
      url: "https://asuiot12.000webhostapp.com/addCourse.php",
      headers: {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,PATCH,OPTIONS",
      },
      data: {
        Course_Code: inputTagCourseCode,
        Course_Name: inputTagCourseName,
        Credit_Hours: inputTagCreditHours,
      },
    })
      .then(function (response) {
        console.log(response);
        alert(response);
      })
      .catch(function (error) {
        console.log(error);
      });
    //attempt 2
    // axios
    //   .post("https://asuiot12.000webhostapp.com/addCourse.php", {
    //     Course_Code: inputTagCourseCode,
    //     Course_Name: inputTagCourseName,
    //     Credit_Hours: inputTagCreditHours,
    //   })
    //   .then(function (response) {
    //     console.log(response);
    //     alert(response);
    //   })
    //   .catch(function (error) {
    //     console.log(error);
    //   });
  };
Button Used:
<button
 style={{ float: "right" }}
 type="button"
 class="btn btn-success button_style mb-4"
 onClick={() => newCourse()}
>
Save Course
</button>
Php Code:
<?php
    include_once 'connection.php';
    class course{
        public $success;
        public $message;
    }
   // header("Access-Control-Allow-Origin: *");
   header("Access-Control-Allow-Origin: *");
   header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
   header('Access-Control-Allow-Headers: *'); 
   header('Access-Control-Max-Age: 1728000');
   header("Content-Length: 0");
   header("Content-Type: text/plain");
    $Course_Code = $_POST['Course_Code'];
    $Course_Name = $_POST['Course_Name'];
    $Credit_Hours = $_POST['Credit_Hours'];
    $query = "INSERT INTO Courses(Course_Code, Course_Name, Credit_Hours)
     VALUES ('$Course_Code','$Course_Name','$Credit_Hours')";
    if(mysqli_query($con,$query)){
        echo "Records added successfully.";    } else{
        echo "ERROR: Could not able to execute $query. " . mysqli_error($con);
    }
    mysqli_close($con);
?>
