MySql PHP query id varchar does it as a numeric

0

I have a MySql database, a student id is a varchar of 11, numbers are stored in this field but can start in zeros. for example 00000321. but it can also store 000321, but when consulting through jquery to PHP with id 0321 without the leading zeros, it shows any of the above or the first one it finds.

the code where the data is sent to php is the following:

$.post("llenadoAl.php", {"id":$(".id_alm").val()}, function(data)

to handle this class of codes varchar was created and can not be numeric because it would eliminate the zeros at the beginning of the id.

How can I make the query find the code exactly the same with the leading zeros?

    
asked by JOHNY G 05.07.2017 в 08:23
source

1 answer

1

I understand that your $_Post is sent correctly (with the 0s that you comment etc ...). The first thing you should do is save your $_Post

$texto = $_POST["id"];

Print it to see if the thing is going well. Check step by step if it is happening correctly, so you will see where you fail.

Finally, the only thing you will have to do is use your variable in the query:

$query = "SELECT * FROM nombre_tabla WHERE ID = '".$texto."'";
    
answered by 05.07.2017 в 10:17