JQuery Ajax Internal Server Error with PHP Call

I’m quite new to this stuff and so far, I could get it working when I would pass only 1 $_POST variable.

However in this case, I’m trying to pass 2 variables and for some reason I’m getting an Internal Server Error as result. Now I have done some trace and it’s definitely not an SQL error. I’m sure the Error stems from the Ajax part, where I’m passing the POST but I can’t figure out what I’m doing wrong. Could anyone help with this?

Here’s my Ajax code:

    var split = this.id.split('_');
    var catID = split[0];
    var myData = 'catToInsert='+ $id; //build a post data structure
    var categoryId = 'category='+catID;

        type: "POST", // HTTP method POST or GET
        url: "includes/category.php", //Where to make Ajax calls
        dataType:"html", // Data type, HTML, json etc.
        data:{myData: myData, categoryId: categoryId}, //Form variables
        error:function (xhr, ajaxOptions, thrownError){
            //On error, we alert user


And here is my PHP:

    $id = $_POST['catToInsert'];
    $catID = $_POST['category'];

    //Create PDO Object
    //Set Error Handling for PDO
    $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

    $sql = "SELECT category_id from product_category WHERE product_id=$id";

    //Prepare Statement
    $stmt = $con->prepare($sql);

    $result = $stmt->fetchAll();
    $array = array_map('current', $result);

    echo $id;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s