Question: Could you please help me with this situation?

Let's say I have this right now:

**HTML**

```html
<select name="insta_country_code" class="widget-user-country country-selector" data-account-name="
    <?php echo $account1['Username'] ?>">
    <option value="br">Brazil</option>
    <option value="cl">Chile</option>
    <option value="es" selected>Spain</option>
    <option value="mx">Mexico</option>
    <option value="gb">United Kingdom</option>
    <option value="cr">Costa Rica</option>
</select>

```

**JS**

```js
$(document).ready(function () {
    $('.country-selector').change(function () {
        var ig_name = $(this).data('account-name');
        var country_code = $(this).val();
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: 'change-country.php',
            data: {
                insta_user: ig_name,
                country_code: country_code,
            },
            success: function (data) {
                if (data['status'] != 1) {
                    $.alert('server error');
                }
            },
            error: function () {
                $.alert('error');
            }
        });
    })
});

```

What should be my `.php` file? I need to do something like this:

```php
$InstagramCountry = $data['country_code'];
$InstagramUsername = $data['insta_user']);

$sql = mysql_query("UPDATE igaccounts SET Country='$InstagramCountry' WHERE Username='$InstagramUsername'");

```

Thank you so much!

Answer: 
As you're using `POST` method to send data to your server side php code, you can catch the data using `$_POST` OR `$_REQUEST` global variable like this-

```
$InstagramCountry = $_POST['country_code'];
$InstagramUsername = $_POST['insta_user']);

```

You said vai comment that you're getting error on ajax call, you can try this way to debug what is the reason of that error using-

```
error: function(xhr, textStatus, error){
      console.log(xhr.statusText);
      console.log(textStatus);
      console.log(error);
  }

```

To capture mysqli error, (I urge you to use **mysqli** and avoid to use the old/deprecated **mysql**), SEE [MORE](http://php.net/manual/en/function.mysql-query.php)

```
$result = mysql_query('UPDATE igaccounts SET Country='$InstagramCountry' WHERE Username='$InstagramUsername');

if (!$result) {
    die('Invalid query: ' . mysql_error());
}

```

> 
> For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
>  mysql\_query() returns TRUE on success or FALSE on error.
> 
> 
>
Hi you can do it this way:

your php script:

```
                  if (isset($_POST["action"])) {
                          $action = $_POST["action"];
                          switch ($action) {
                              case 'SLC':
                                  if (isset($_POST["id"])) {
                                      $id = $_POST["id"];
                                      if (is_int($id)) {
                                          $query = "select * from alumni_users where userId = '$id' ";
                                          $update = mysqli_query($mysqli, $query);
                                          $response = array();
                                          while($row = mysqli_fetch_array($update)){
                                          .......
                                          fill your response here

                                          }
                                         echo json_encode($response);
                                      }
                                  }
                                  break;

                          }
                      }

```

Where action is a command you want to do SLC, UPD, DEL etc and id is a parameter

then in your ajax:

```
                function getdetails() {
                      var value = $('#userId').val(); // value can be your array ! note: if you send a object json_encode(json_decode(,MyObj,true))
                     return $.ajax({
                          type: "POST",
                          url: "getInfo.php",
                          data: {action: "SLC",id: value }
                      })
                  }

```

call it like this:

```
    getdetails().done(function(response){
                  var data=JSON.parse(response);
                  if (data != null) {
                  //do somthing with your Data
                  }
                  })

```

Hope it Helps