0
SELECT * FROM hge_funcionarios 
 JOIN hospitais
 ON hge_funcionarios.hospital_id = hospitais.id_hospitais 
 JOIN funcoes
 ON hge_funcionarios.funcao_id = funcoes.id_funcoes
WHERE nome LIKE '%$search%'
ORDER BY hospital_id DESC

When I try the exact name from the database doesnt show up any results. If i search "Larissa" or "LARISSA", I get no results even in my database having "LARISSA CAMPOS".

If I try "lar" or anything like this I can find it, but when it gets too close to the name on database like "LARISS" I can't find it any more. I tried collate and charset but no success.

EDIT: Its not a Query error with ambiguous column name in SQL because column names are distinct.

Bobby Axe
  • 1,491
  • 13
  • 29

2 Answers2

1

I'm writing this answer since it's not possible to show it in the comments. Feel free to disregard it.

The problem you are facing seems to be related to the injection of parameter values into your SQL query. The easy (dangerous) way is to simply concatenate strings, as in:

$stmt = $conn->prepare(
  "select * from my_table where name = '" . $param1 . "'");

Even though it works for simple cases, your case is more complicated, and confusing. Most of the time you'll use Prepared Statements as in:

$stmt = $conn->prepare("select * from my_table where name = ?");
$stmt->bind_param("sss", $param1);

This way, the parameter will be injected the right way. In your case you'll need to prepend and append % to your parameter, since it'll be used for a LIKE operator.

The Impaler
  • 45,731
  • 9
  • 39
  • 76
-1
WHERE nome LIKE '%$search%'

May be $ is the Reason.Try Like : WHERE nome LIKE '%search%'

Anji
  • 35
  • 6