Note to future visitors.
The original closure of their question was based on their original post where they were using mysql_fetch_array
without the i
, and changed it before it could be recorded in revisions.
Then completely changed their code https://stackoverflow.com/revisions/34335181/3 after I posted my answer.
Original answer based on the above
So you changed mysql_fetch_array
to mysqli_fetch_array
after I closed the question about your mixing MySQL APIs.
It is unclear as to which MySQL API you're using to connect with. mysql_
, mysqli_
, or PDO (those different APIs do not intermix).
Plus, you're not checking for errors.
Also, no idea what variable you are using to connect with.
What's going on here is that you're not connecting to your query and I do not know what variable you are using.
So, base yourself on the following and change the variable to the one you're using in your connection file:
$result = mysqli_query($connection, "SELECT ...
mysqli_query()
requires a connection:
Add error reporting to the top of your file(s) right after your opening PHP tag
for example
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
then the rest of your code, to see if it yields anything,
as well as or die(mysqli_error($connection))
to mysqli_query()
.
Your HTML form is also unknown, and if it is using a POST method and if the input does have the name attribute for it.
I.e.:
<form method="post" action="your_handler.php">
<input type="text" name="id">
</form>
- Forms default to a GET if a POST method isn't specifically set. Therefore, that would trigger/cause an undefined index notice.
Sidenote: Make sure there are no whitespaces in your input/query. Use trim()
and var_dump()
as an additional tool.
Plus, if you're looking for an exact match, don't use LIKE, but a WHERE iddistrito = '$pesq'");
Read up on LIKE: http://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html
There are wildcards you can use, if pattern matching is required.
Your present code is open to SQL injection. Use mysqli_*
with prepared statements, or PDO with prepared statements.