mysqli_query() Function Requiring at Least Two Parameters
The error message, "mysqli_query() expects at least 2 parameters, 1 given," indicates that the function is not receiving enough parameters to execute successfully.
In PHP, the mysqli_query() function requires two parameters:
Applying the Fix
In your provided code:
<code class="php">$search_query=mysqli_query($search_sql);</code>
the mysqli_query() function is missing the first parameter, which is the link to your MySQL connection. You need to pass the connection resource created by mysqli_connect() as the first parameter.
<code class="php">$search_query=mysqli_query($con, $search_sql);</code>
Additional Information
The other errors, related to mysqli_num_rows(), are likely caused by the fact that $search_query is initially null because of the missing connection resource. Once you fix the mysqli_query() call, the mysqli_num_rows() calls will also work correctly.
The above is the detailed content of Why is mysqli_query() throwing \'expects at least 2 parameters, 1 given\'?. For more information, please follow other related articles on the PHP Chinese website!