jerneva
jerneva

Reputation: 465

What are parameters in php?

What are parameters in php?

I have looked online, and there are many different definitions, which is confusing for a newbie like myself.

The reason i ask is because i have the following error:

Warning: mysqli_query() expects at least 2 parameters, 1 given in /Applications/MAMP/htdocs/PhpProject2/Area_Rest_page.php on line 22

Based on this code:

$sql=mysqli_query("SELECT Rest_Details.Resturant_ID,    
Rest_Details.Resturant_name, Rest_Details.Res_Address_Line_1, Rest_Details.City_name, 
 Rest_Details.Avg_Del,Delivery_Pcode.Pcode 
 FROM Rest_Details
 INNER JOIN Delivery_Pcode
 ON Delivery_Pcode.Restaurant_ID=Rest_Details.Restaurant_ID
 WHERE Delivery_Pcode.Pcode LIKE '%$searchq'") or die ("could not search!");

Line 22 is:

WHERE Delivery_Pcode.Pcode LIKE '%$searchq'") or die ("could not search!");

Upvotes: 1

Views: 63

Answers (1)

Chris
Chris

Reputation: 59511

It means that mysqli_query needs 2 variables passed to it. The one is the sql query, which you have provided, but it also needs to know to which mysql connection to query against.

Have a read on the official docs for mysqli_query, as well as function arguments.

Information may be passed to functions via the argument list, which is a comma-delimited list of expressions. The arguments are evaluated from left to right.

Here's an example using the function you're trying to use:

$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* Create table doesn't return a resultset */
if (mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
    printf("Table myCity successfully created.\n");
}

In the code above, we're first connecting to the database with mysqli_connect, and we save the return value of that function to the $link variable.

Then, to run our query with mysqli_query we pass in the connection variable ($link) as well as the query.

Upvotes: 1

Related Questions