I want to save data in database, Im using angular and I used a file php to access to database, the problem is : POST http://127.0.0.1:9090/insert_indispo.php 405 (Method Not Allowed).. please how to resolve this problem !......
here my function post:
function ValideConge(id,debut,fin) {
var deferred = $q.defer();
$http({
method: 'POST',
url: window.location.href + 'insert_indispo.php',
data: {id,debut,fin},
headers: { 'Content-Type': 'application/json' }
}).then(function (success){
deferred.resolve("ok!");
console.log("ok c!");
},function (error){
deferred.resolve(false);
console.log("ok n!");
});
return deferred.promise;
}
here my file php :
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$id = $request->id;
$debut = $request->debut;
$fin = $request->fin;
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "plann";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO indisp (id_form,date_debut,date_fin)
VALUES ( $id, $debut , $fin)";
if ($conn->query($sql) === TRUE) {
echo "ajouté avec succé !";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
</div>