Help with PHP function to discard a MySQL data

0

I have the following:

$verf = "SELECT nro_transf FROM pedidos WHERE nro_transf = '$nro_transf'";
$result = mysqli_query($db, $verf);
$rows =  mysqli_num_rows($result);

$verf2 = "SELECT nro_transf FROM pagos WHERE nro_transf = '$nro_transf'";
$result2 = mysqli_query($db, $verf2);
$rows2 =  mysqli_num_rows($result2);

$sumarows = $rows + $rows2;

Practically what I occupy is that if the data provided by the user in my payment declaration form already exists in my database then I do not accept the declaration (These are already declared and functional) as I have it it works if and only if the number that you try to use is exactly the same as the number that exists in my database, but I have found that there are users that if there is already a statement:
nro_transf = 123456
They try to cheat by placing a similar number example:
nro_transf = 1123456
nro_transf = 00123456
nro_transf = 01123456
My question would be: What instruction can I give to my 2 queries so that apart from looking for the number as it was entered it will also do it if the last 6 digits are similar ..!
I know that with the instruction:

WHERE (nro_transf LIKE '%$nro_transf%')   

I can do the filter but it turns out that there are transfers that almost 100% of them start with the same example digits:
0051411234
0051413456
0051416789
Where all are valid transfers but they start with the same number and the ideal is to filter by their last 4 or 6 digits that are different.

    
asked by Jose M Herrera V 16.11.2018 в 16:49
source

2 answers

1

Cuts the string before passing it to the query.

To do this, use the substr function, which will allow you to keep a portion of her.

For example, create a new variable:

$numerocorto = substr($nro_transf, -6);

And that new variable is going to have the last 6 characters of nro_transf.

And then, in your query, do it normally using the condition:

WHERE (nro_transf LIKE '%$numerocorto')   

without the% at the end, since what you are going to do there is bring everything equal to the last 6 digits you previously extracted

    
answered by 16.11.2018 / 17:30
source
-1

Try removing both % so that your search is exactly with the data that your variable carries $ nro_transf that way your search will be exact.

    
answered by 16.11.2018 в 16:56