-1

I am trying to make a web application and I would like to search in a mysql database with a php script. But my code does not work as expected. Here is my code:

$search=$_POST['search'];
$sql_cautare="SELECT * FROM carti WHERE titlu = "$search"";

I have search form..and I want to select those values that are entered in the search form. Can anyone help me?

2 Answers2

0

Try this one

$sql_cautare = $conn->prepare("SELECT * FROM carti WHERE titlu = ?");
$sql_cautare->bind_param('s', $search);
$sql_cautare->execute();
-1

The following should work:

 $sql_cautare = "SELECT * FROM carti WHERE titlu = '$search'";

But you should definitly do some input sanitization before using it in SQL!

Reto
  • 1,305
  • 1
  • 18
  • 32