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.
> 
> 
>
Try this, it should must work for your case. I have tested it in my localhost.
For your HTML File:

```
<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>

```

For your JS File:

```
<script>
            $(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');
                        }
                    });
                })
            });
        </script>

```

For your .PHP File:

```
<?php 
$data = $_REQUEST; 
$InstagramCountry = $data['country_code'];
$InstagramUsername = $data['insta_user'];
echo "insta_user=".$InstagramUsername . " AND country_code=" . $InstagramCountry; exit; 

```

Tell me if still need any help bro.