Home > Database > Mysql Tutorial > 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
Release: 2024-11-01 22:55:29
Original
864 people have browsed it

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>
Copy after login

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>
Copy after login

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

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

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template