I'm calling send Array function and I'm hoping to create and array and send it to my PHP file. I want the PHP to extract the data and enter the values into the columns in a mySQL database.
function sendArray(){
var name = "John";
var address = "UK"
var sendInfo = {
Name: name,
Address: address,
};
$.ajax({
url: "http://server/~name/folder/insertOffer.php",
type: "POST",
dataType: "json",
data: {data: sendInfo},
})
.done(function(msg) {
if (msg) {
alert("Somebody" + name + " was added in list !");
location.reload(true);
} else {
alert("Cannot add to list !");
}
});
}
<?php
include("mysqlconnect.php");
$sendInfo = file_get_contents('php://input');
$data = [];
$Name = $_POST['data']['name'];
$Address = $_POST['data']['Address'];
mysqli_query($con,"INSERT INTO offerSelected (Id, Url)
VALUES ('$name', '$address')");
?>