What I'm trying to do
The intention of my program is to insert data from a local HTML/JS website into an online (non-local) mySQL database.
What I've attempted so far
The original method I was attempting to utilise to accomplish this was to, have my local website utilise javascript to post data via an online PHP file, then have this PHP file insert this information into a mySQL table. But I kept receiving cross-origin request related errors.
After reaching a wall programmatically, I opened up a Stackoverflow Thread to determine whether it was even possible to post from a local website to an online PHP file, during which I was expertly informed this wasn't possible without modifying Chrome related policies on each machine attempting to visit this local website.
Purpose of this thread
To determine whether rather than posting via a PHP file to enable the inserting of data into a mySQL table from a local HTML/JS website, if there is another approach I've not considered.
Reasoning for not modifying browser policies:
I don't have control over which policies are implemented on user browsers or which browser they choose to utilise. Similarly I'm not able to install additional software onto their systems e.g. Apache etc.
Overall Problem
As the methods I've attempted so far to post from a local HTML/JS website as a means to insert into a mySQL database have so far been unsuccessful. I've posted here to determine whether there was another approach that I have not yet considered rather than posting data via PHP files, which could be applied to my source code, rather than a user's web-browser to allow for the execution of mySQL queries initiated from a local HTML/JS website?
JS Code:
function uploadPetData(petName, petAge, petType) {
var urlString ="Pet_Name="+petName+"&Pet_Age="+petAge+"&Pet_Type="+petType;
$.ajax({
type: 'POST',
url: 'http://example.com/test.php',
crossDomain: true,
data : urlString,
contentType:contentType,
success: function(responseData, textStatus, jqXHR) {
var value = responseData.someKey;
}
});
}
PHP Code:
<?php
$con=mysqli_connect("...","...","...","...");
$petName = $_POST['Pet_Name'];
$petAge = $_POST['Pet_Age'];
$petType = $_POST['Pet_Type'];
$petName = mysqli_escape_string($con, $petName);
$petAge = mysqli_escape_string($con, $petAge);
$petType = mysqli_escape_string($con, $petType);
$query = mysqli_query($con, "INSERT INTO Pets (Name, Season, Episode)
VALUES ('$petName', '$petAge', '$petType')");
mysqli_close($con);
?>
HTML/JSwebsite to the onlinemySQLdb table. The first would simply insert a row into the onlinemySQLdb table mentioned above. The second would determine whether a particular row existed within the onlinemySQLdb table and if determined as present, aTRUEorFALSEvalue would be returned.htmldocumentonline for user to submit<form>, and get response from server?mySQLdb table, why not simply put the whole website online. The reason I don't want to put full website online is, I want the website itself to be completely private to a number of selected users. But information can be shared between these localHTML/JSweb-pages via the use of data provided by and uploaded to the onlinemySQLdb table. If I've misunderstood what you mean please correct me, as I'm really hoping for an applicable solution to the above mentioned problem.