Question: I have one textfield type text, when I'm typing a number of a plate, if it exist, it will must show one alert, but the event keyup doesn't work.

JS

```
$('#mat').keyup(function(){
        var matric = $('#mat').val();
        $.ajax({type: "POST",
                     url: "compruebaVeh.php",
                     data: "matric="+matric,
                     success:function(data) {
                         alert(data);
                         if(data=='ok'){
                             alert('this car already exists');
                         }
                     }
        });  
    });

```

PHP

```
<?php

 $mat=$_POST['matric'];
 ini_set('display_errors',1); error_reporting(E_ALL);
 require('conecta.php');
 $cSQL="select matricula from vehiculos;";
 $stmt=$oConni->prepare($cSQL) or die($oConni->error);
 //$stmt->bind_param('s',$_POST['matric']);
 $stmt->execute();
 $stmt->bind_result($matricula);
 while ($stmt->fetch()) {
    if($matricula==$mat){
        echo 'ok';
    }
 }   
 $stmt->close();  
?>

```

Answer: 
in php code, the assignment `$_POST['matric']=$mat;` should be reversed

`$mat = $_POST['matric'];`

also your script may echo `ok` many times depending on the data in your DB, the loop should become:

```
while ($stmt->fetch()) {
    if($matricula==$mat){
        echo 'ok';
        break;
    }
 }  

```

so now you could compare in js callback with "ok".
in the most cases there id #mat is defined more than one time in the html code, also the keyup might work, but the url may not be correct, and it will not trigger the success branch. Other than that i see $\_POST['matric']=$mat; wich isn't quite right. Probably you wantedd $mat = $\_POST['matric']. You can check using firebug console what really happens with the javascript and what the php script returns