-2

I am trying to send 2 values from cx_card to my getproduto.php. For this I am using ajax

The variable values:

com_id=1

cliente_id=3440

The form select:

<select width="200" name="produto" id="produto-list" class="produtoInputBox" onChange="getsubproduto(this.value);" <?php echo $permissao; ?>>

ajax code

function getproduto(val,val_id) {
$.ajax({
type: "POST",
url: "inc/cx/get_produto.php",
data:'com_id='+val+'&cliente='+val_id,
success: function(data){
  $("#produto-list").html(data);

  }
 });
}

My Query in getproduto.php

$query ="SELECT * FROM apolices WHERE id_cliente='".$_POST['cliente_id']
        ."' and id_companhia = '".$_POST['com_id']."'";
$results = $db_handle->runQuery($query);

In cx_card i have print the query i have recibe from getproduto.php the result is:

SELECT * FORM apolices WHERE id_cliente='undefined' and id_companhia='1'

Thanks for the help.

halfer
  • 19,824
  • 17
  • 99
  • 186
FreeLancer
  • 79
  • 1
  • 6
  • 13
  • 1
    What did you expect? You're only passing in one argument, `val` and using that for both arguments in data. If you want two different values then pass in two arguments to getproduto. – Styphon May 06 '16 at 15:42
  • **Danger**: You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that you need to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin May 06 '16 at 15:42
  • If you have 2 variables on php why do you have only 1 in jquery ? – Pedro Lobito May 06 '16 at 15:45
  • Quentin this website is only allowed for 10 people acess in the work thanks for the warning – FreeLancer May 06 '16 at 15:50

2 Answers2

1

You're only passing one argument to your getproduto function. If you want two different values you need two different arguments. Try this:

function getproduto(com_id, cliente_id) {
    $.ajax({
        type: "POST",
        url: "inc/cx/get_produto.php",
        data:'com_id='+com_id+'&cliente_id='+cliente_id,
        success: function(data){
            $("#produto-list").html(data);
        }
    });
}
Styphon
  • 10,304
  • 9
  • 52
  • 86
1

You're only sending in one value:

function getproduto(val) {
    $.ajax({
    type: "POST",
    url: "inc/cx/get_produto.php",
    data:'com_id='+val+'&cliente_id='+val,
    success: function(data){
    $("#produto-list").html(data);

   }
  });
}

You should be sending two:

function getproduto(val,val_id) {
    $.ajax({
    type: "POST",
    url: "inc/cx/get_produto.php",
    data:'com_id='+val+'&cliente_id='+val_id,
    success: function(data){
    $("#produto-list").html(data);

   }
  });
}
durbnpoisn
  • 4,666
  • 2
  • 16
  • 30