Home  >  Article  >  Database  >  Why am I getting the \"mysqli_query() expects at least 2 parameters, 1 given\" error?

Why am I getting the \"mysqli_query() expects at least 2 parameters, 1 given\" error?

Susan Sarandon
Susan SarandonOriginal
2024-11-01 22:55:29777browse

Why am I getting the

mysqli_query() Parameter Discrepancy: Troubleshooting "1 Parameter Given" Error

The error "mysqli_query() expects at least 2 parameters, 1 given" indicates that the mysqli_query() function is missing a required parameter. This function requires two parameters: the MySQLi connection resource and the SQL query statement. In the provided code snippet:

<code class="php">$search_query = mysqli_query($search_sql);</code>

The connection resource is missing. To resolve this issue, specify the connection resource as the first parameter, as follows:

<code class="php">$search_query = mysqli_query($con, $search_sql);</code>

Here, $con represents the MySQLi connection established earlier in the code:

<code class="php">$con = mysqli_connect('localhost', 'sagginev_rob', '122989', 'sagginev_Nutrifitness');</code>

Once the correct number of parameters is provided, the mysqli_query() function can execute the SQL query successfully.

The above is the detailed content of Why am I getting the \"mysqli_query() expects at least 2 parameters, 1 given\" error?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn