I am trying to make a search engine with PHP and SQL, it is throwing me an error that I really do not understand why it is due and it is the following:
mysqli_query() expects at least 2 parameters, 1 given
My code: index.php
<?php
mysqli_connect("localhost","root","","testing") or die ("DB Error");
$output = '';
//collect
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace ("#[^0-9a-z]#i", "", $searchq);
$query = mysqli_query("SELECT * FROM posts WHERE title LIKE '%$searchq%'") or die ("error del query");
$count = mysqli_num_rows($query);
if ($count == 0){
$output = 'No se han encontrado resultados!';
} else {
while($row = mysqli_fetch_array($query)) {
$tname = $row['title'];
$output .= '<div>'.$tname.'</div>';
}
}
}
?>
<div class="search">
<button onclick="show_hide()" class="searchButton">
<i class="fa fa-search"></i>
</button>
<form action="index.php" method="post">
<input type="text" id="input" name="search" class="searchTerm" placeholder="Buscar anime..."/>
</form>
</div>
I have been checking and everything is written correctly regarding the database.
mysqli_query() uses 2 parameters, the first is the connection and the second is the query.
What would I do:
Source: https://www.php.net/manual/en/mysqli.query.php