I have a simple problem but I couldn't find out the solution. the below code is my POST ajax code.
once Its submitted I got the result from the PHP file.
once this alert is work alert(addcenterresult);
if OK its alerted 1 if not 2
but the result if every time showing alert ("SomeThing Wrong");
I checked my PHP everything is good. I assumed the error in my ajax code but I found nothing !!!
Please can you help
$('#add-jeddah').click(function () {
var centername = $('#JeddahCenterNAme').val();
var dataString = 'centername=' + centername;
if (centername == '') {
alert("Please write the center name");
} else {
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "func/addjeddahCenter.php",
data: dataString,
cache: false,
success: function (addcenterresult) {
alert(addcenterresult);
if (addcenterresult == "1") {
alert("Well Done");
} else {
alert("SomeThing wrong");
}
}
});
}
// END add-Jeddah function
});
My PHP
$nameCenter = $_POST['centername'];
$addresult = "INSERT INTO centers (id,centerName) VALUES ('','$nameCenter')";
if (mysql_query($addresult)) {
echo "1";
} else {
echo "2";
}