From telephony comes the phone number in the API of the system, at this point you need to perform a search by phone number ...

My code is:

//$phone_client - переменная содержит номер телефона. $result_client = mysql_query("SELECT * FROM `lids` WHERE id_cabinet = '$id_cabinet'"); // ограничиваем поиск до нужного кабинета $myrow_client = mysql_fetch_array($result_client); if ($myrow_client['tel'] == $phone_client) { //если совпадение найдено, то добавляем id клиента в поле по id звонка } 

How to make the search more correct and with the minimum number of errors that was?

Closed due to the fact that the essence of the question is not clear to the participants of Dmitriy Simushev , cheops , Bald , HamSter , user207618 3 Oct '16 at 5:33 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Apparently you do not need to read the entire table but explicitly set the condition with the phone number in the sql query itself - Mike
  • And do not put the values ​​of variables in the request itself, but use the bound parameters. see mysqli_bind_param () - Mike

1 answer 1

You need to choose a single style for storing numbers, so that you can further bring the number to the same type and look in the database.

For example, you can at least remove all that are not numbers:

 $phone_number = preg_replace('/[^0-9]/', '', $phone_number); //save phone 

When searching in the same way, delete all that is not numbers from the string and search in the database:

 $phone_client = preg_replace('/[^0-9]/', '', $phone_client); //Выбираем только одну запись $sql = "SELECT * FROM `lids` WHERE id_cabinet = :room AND tel = :phone LIMIT 1"; $pdo->prepare($sql); $pdo->execute([':room'=>$id_cabinet, ':phone'=>$phone_client]); if(($result = $pdo->fetch()){ print_r($result); }; 

mysql - This extension has been deprecated since PHP 5.5.0, and has been removed from release 7.0.0. Use mysqli or PDO

The principle is how to store user passwords, when you save, encode, when searching, encode the received password and compare it with what is in the database.

If you can receive different formats, for example, you have saved with a country code, or a number without a code can come in, you can simply search by the occurrence of a string ( sql_like ).

You can try to use the library libphonenumber , with its help you can get information about the number, check for validity, choose one of the formats.

  • Thanks, I know about mysql, I'm afraid to just go to the last ... I feel all the site codes will have to be shopped ... - Alexander Sizintsev
  • it makes no sense for a couple to transfer old and big projects to a new one, but people can find the answer later, and many accept the code on faith, as a result, many now use mysql simply because they find them in old answers, guides, etc. - Bookin
  • I have a crm system project, I'm afraid to transfer it to a new php simply because people work there almost constantly ... but I know that sooner or later it will have to be done, because otherwise it will not be possible to develop its capabilities ... - Alexander Sizintsev
  • Well, if you plan to develop the system, then of course it is worth addressing this issue. Moreover, no one forces you to do everything at once, add a config for the base through a different extension, and replace it with parts, there will be a project where there will be a part on the old part on the new one, the main thing is to gradually reduce the other part and gradually move to the new one. - Bookin
  • in principle, and thought. Now it's time to enter the socket for calling the client's card - Alexander Sizintsev