-4

The first File is: form.php.

I can't send the values (1 or 2) to my other file.

Can anyone help me out?

$(function () {
    $('#cod_cidades').change(function () {
        if ($(this).val()) {
            $('#s').hide();
            var valor = ($(this).val());
            $('.carregando').show();
            $.getJSON('vara.ajax.php', { cod_cidades: $(this).val(), ajax: 'true' }, function (j) {
                var options = '<option value=""></option>';
                for (var i = 0; i < j.length; i++) {
                    options += '<option value="' + j[i].s + '">' + j[i].nome + '</option>';
                }
                $('#s').html(options).show();
                $('.carregando').hide();
            });
        } else {
            $('#s').html('<option value="">– Escolha um estado –</option>');
        }
    });
});

Varas.ajax.php

This is the part that i get the value.

$id_cidade = mysql_real_escape_string( $_REQUEST['cod_cidades'] );
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252

2 Answers2

0

"mysqli, I don't thin that this is the problem." - Err... yes that is a problem, if not THEE problem. mysql_real_escape_string() does NOT mix with mysqli_ and mysql_real_escape_string( $_REQUEST['cod_cidades'] ) will never populate and is probably why your code is failing. Fred -ii- 7

0

This (and I had a feeling that's what the problem was) "Spidey sense tingling".

mysql_real_escape_string( $_REQUEST['cod_cidades'] )

and you mentioned in comments that you are using mysqli_ to connect with, after my asking you about it.

That MySQL function does not mix with mysqli_.

You need to use its mysqli_ equivalent:

mysqli_real_escape_string($connection, $_REQUEST['cod_cidades'] )

You will need to change the $connection variable to match the one you are using.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141