Home > Database > Mysql Tutorial > body text

Why is mysqli_query() throwing \'expects at least 2 parameters, 1 given\'?

Linda Hamilton
Release: 2024-11-02 05:23:02
Original
530 people have browsed it

Why is mysqli_query() throwing

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:

  • Resource: A link to a MySQL connection (i.e., mysqli_connect() return value)
  • Sql: The SQL query to execute

Applying the Fix

In your provided code:

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

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!