I use this Javascript to post data from different variables to a php file that updates a Mysql database:
$.ajax({
url: "createchild.php",
type: 'POST',
data: ({ATU:ATUv,AM:AMv,ATS:ATSv,segment:segmentv,acrcat:acrcatv,owner:childowner,topparent:childtp}),
success: function(msg) {
console.log(msg);
}
Then this gets sent to the createchild php file:
<?php
header('Content-type: text/plain; charset=utf-8');
$servername = "xxxxxxxxxxxxx";
$username = "xxxxxxxxxxxxxxxxxxxx";
$password = "xxxxxxxxxxxxxxx";
$dbname = "xxxxxxxxxxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql ="INSERT INTO tablename (top_parent, qualified,retry,partner_attached,partner_name,migration,sap,AM,ATS,ATU,owner,engagement,segment,acr_cat,childtp)
VALUES ('" . $_POST['childname'] . "','No','Unknown','No','Unknown','Not Qualified','Not Qualified','" . $_POST['AM'] . "','" . $_POST['ATS'] . "','" . $_POST['ATU'] . "','" . $_POST['owner'] . "','No','" . $_POST['segment'] . "','" . $_POST['acrcat'] . "','" . $_POST['topparent'] . "'); ";
if ($conn->multi_query($sql) === TRUE) {
echo "New record created successfully";
echo "".$_POST['childname']."";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
echo "".$_POST['childname']."";
}
$conn->close();
?>
The query runs successfully and a line gets created in my database. However all the columns where I use "$_POST['xx']"
are empty, so no data gets passed on to the php file it seems.
All the variables in the js file (AMv, ATUv, ATSv...) do contain data (i've checked with an alert) but the php file can't seem to read the post.
Any idea why and where the data gets stuck?