I am making an AJAX call to a php file on my local domain. I am running into an issue as it is not returning any data for the success function in the request.
I am serializing a form to post data to go into a DB. I can get this working just fine and it is writing to the database.
The issue is when I try to get the echoed statement to show in the data part of the success function.
I have used alert and it doesn't alert anything. I have tried a console.log and that just shows:
(an empty data string)
I had it working before I switched from mysql_ functions to PDO functions. Now it just isn't returning anything. I have had a look around and this link in particular and it still isn't working.
This is what I have in the ajax post request:
var formstuff = $('#person-data').serialize();
$.ajax(
{
url: 'insert.php',
type: "POST",
dataType: 'text',
data: formstuff,
success:
function(data)
{
console.log(data);
alert(data);
$('#info').hide();
$('#info').html('');
$('#info').append(data);
$('#info').fadeIn(1500);
$("#person-data")[0].reset();
$('#username').css({'border': '1px solid #000', 'background-color': '#FFF', 'color': '#000'});
$('#username').css('background-image', 'url(images/txtbox/id.png)');
}
});
I have checked the posted headers in the console and it is posting what is entered into the form fields.
This is the echo that I have that I want returned to the success function:
echo 'ID: '.$idp.' Lastname: '.$ln.' First Name: '.$fn.' added to the database';
This is just not being returned to the success function. I have tried this without using the try...catch. I have put it inside the try and nothing. The catch error is being sent back to the function as it should be.
I have tried to echo something before the try and then outside of the catch and the echo before the try is outputted to the success function, just not the data I need.
I have also tried if statements to see if that will work and it isn't displaying anything.
I am stumped and just wondered if there were some pointers I could get.
TIA
Edit
PDO info:
try
{
$sqlp = $conn->prepare("INSERT INTO ".PERSON." (lastname, firstname, dob, adbkid) VALUES(:ln, :fn, :dob, :unp)");
$sqla = $conn->prepare("INSERT INTO ".ADDRESS." (address1, address2, town, county, postcode, country, lat, lng, personID) VALUES (:a1, :a2, :town, :county, :pc, :country, :lat, :lng, :una)");
$sqlc = $conn->prepare("INSERT INTO ".CONTACT." (landline, mobile, email1, email2, personID) VALUES (:lp, :mp, :e1, :e2, :unc)");
$sqlm = $conn->prepare("INSERT INTO ".MISC." (web, notes, photo, fbid, twitter, cat, personID) VALUES (:web, :notes, :pic, :fb, :tw, :cat, :unm)");
$sqlv = $conn->prepare("INSERT INTO ".VARI." (Time, Date, ipaddress, browser, os, personID) VALUES (:it, :idate, :iip, :ib, :ios, :unv)");
$sqlp->bindValue(':ln', $ln);
$sqlp->bindValue(':fn', $fn);
$sqlp->bindValue(':dob', $dob);
$sqlp->bindValue(':unp', $un);
$sqla->bindValue(':a1', $a1);
$sqla->bindValue(':a2', $a2);
$sqla->bindValue(':town', $town);
$sqla->bindValue(':county', $county);
$sqla->bindValue(':pc', $pc);
$sqla->bindValue(':country', $country);
$sqla->bindValue(':lat', $lat);
$sqla->bindValue(':lng', $lng);
$sqla->bindValue(':una', $un);
$sqlc->bindValue(':lp', $lp);
$sqlc->bindValue(':mp', $mp);
$sqlc->bindValue(':e1', $e1);
$sqlc->bindValue(':e2', $e2);
$sqlc->bindValue(':unc', $un);
$sqlm->bindValue(':web', $web);
$sqlm->bindValue(':notes', $notes);
$sqlm->bindValue(':pic', $pic);
$sqlm->bindValue(':fb', $fb);
$sqlm->bindValue(':tw', $tw);
$sqlm->bindValue(':cat', $cat);
$sqlm->bindValue(':unm', $un);
$sqlv->bindValue(':it', $it);
$sqlv->bindValue(':idate', $idate);
$sqlv->bindValue(':iip', $iip);
$sqlv->bindValue(':ib', $ib);
$sqlv->bindValue(':ios', $ios);
$sqlv->bindValue(':unv', $un);
$sqlp->execute();
$sqla->execute();
$sqlc->execute();
$sqlm->execute();
$sqlv->execute();
$idp = $sqlp->lastInsertId();
$ida = $sqla->lastInsertId();
$idc = $sqlc->lastInsertId();
$idm = $sqlm->lastInsertId();
$idv = $sqlv->lastInsertId();
echo $idp.' '.$ln.' '.$fn.' added';
}
catch (PDOException $e)
{
print '<div class="sqlerror">'.$e->getMessage().'</div>';
}
This is what is returned and the response is shown in the file using mysql
This is what is returned when using PDO - no data and no response