Do a sample
$result = $mysqli->query("SELECT time FROM LeadsTable WHERE phone = $phone LIMIT 1"); How to determine if there is an entry in the database?
Do a sample
$result = $mysqli->query("SELECT time FROM LeadsTable WHERE phone = $phone LIMIT 1"); How to determine if there is an entry in the database?
If $mysqli is an object of the native class mysqli , then the query method for a select query will always return a result object if the query was executed without errors. No rows found - this is a special case of successful execution. And casting an object to a boolean type is always true . Therefore, if ($result) , of course, will only say that the request has been completed.
You need to check or the number of lines in the result:
if ($result->num_rows > 0) Or call any of the fetch_ methods to get the result string. If fetch says NULL , then no rows were found.
Note the possible SQL injection. In general, never substitute data in the query text and use prepared statements . Then you will not have to worry about this question, and the use of a variable in the query text should cause anxiety and a desire to check what the variable is and whether it should be inserted as is.
Source: https://ru.stackoverflow.com/questions/582025/
All Articles
if ($result)means returned what was requested - Alexey Shimanskyне работает..... and of course the code together, not divorced from ...... - Alex Shimansky