I have a php file in the C:inetpubwwwroot
directory, which is being hosted via IIS(version 10) on my computer. I also have an SQL server running with XAMPP, i just used PHPMyAdmin to make some tables. The code in this php file connects with the database, to add a row to a specific table. Furthermore, i have a little website with html+css+JS. the JS for that website is:
window.onload = function(){
$('#inputBTN').click(function() {
var request = $.ajax({
url: "C:/inetpub/wwwroot/werkthet.php",
data: { label: "value" },
method: "POST"
});
request.done(function() {
});
});
};
i want to Post to the php file:
<?php
$servername = "localhost:3306";
$username = "root";
$password = "";
$dbname = "albums";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "INSERT INTO metal (TITLE, ARTIST, YEAR, RATING, PRISG, SECSG)
VALUES ('Crimson', 'Edge of sanity', '1994', 3.94, 'death metal', 'progressive metal')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$method = $_SERVER['REQUEST_METHOD'];
print_r($method);
$conn->close();
?>
This file works when i reload the page http://localhost/werkthet.php
. It adds a row to the table. From what i understood, the POST method in JS makes this file basically do its thing. But the problem is, that C:inetpubwwwroot
‘s access is denied(my error: jquery-1.11.0.min.js:4 Not allowed to load local resource: file:///C:/inetpub/wwwroot/werkthet.php). I have tried to set all permissions to allow everything(in the properties -> security) but its doing a bit weird but i at least have permission myself to paste and remove files there.
is there a way i could let javascript post to the php file succesfully? maybe a virtual directory? would that help?
Ive tried to just fill in the directory of the file, but also the actual URL(http://localhost/werkthet.php), but that gave a different error. this seemed better.