mysqli_query() expects at least 2 parameters, 1 given in? [duplicate]
I keep getting the same 3 errors every time I run this php. I have no clue what I am doing wrong, can anyone help?
Here are the errors:
[05-May-2014 19:20:50 America/Chicago] PHP Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/sagginev/public_html/Nutrifitness/search.php on line 10
[05-May-2014 19:20:50 America/Chicago] PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/sagginev/public_html/Nutrifitness/search.php on line 11
[05-May-2014 19:20:50 America/Chicago] PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/sagginev/public_html/Nutrifitness/search.php on line 16
here is my code
enter code here
<?php
$con=mysqli_connect('localhost','sagginev_rob','122989','sagginev_Nutrifitness');
if (mysqli_connect_errno()) // Check connection
{ echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
if(!isset($_POST['search'])) {
header("Location:home.php");
}
$search_sql="Select * FROM Questions WHERE username LIKE '%".$_POST['search']."%' OR feedback LIKE '%".$_POST['search']."%'";
$search_query=mysqli_query($search_sql);
if(mysqli_num_rows($search_query)!=0) {
$search_rs=mysqli_fetch_assoc($search_query);
}
?>
<H2> Search Results</H2>
<?php if(mysqli_num_rows($search_query)!=0) {
do { ?>
<p><?php echo $search_rs['name']; ?> </p>
<?php } while ($search_rs=mysqli_fetch_assoc($search_query));
} else {
echo "No results found";
} ?>
<form>
<br>
<input type="button" value="Go Back Home" onClick="parent.location='http://sagginevo.com/Nutrifitness/home.php'">
</form>
Solution 1:
The error message is quite clear. mysqli_query()
requires two parameters. You only provide one. When you see an error message like this the first thing you need to do is go to the manual. If you did you would see you must provide your MySQLi link as the first parameter:
$search_query=mysqli_query($con, $search_sql);
Solution 2:
You need to add the connection variable as the first argument which in this case is $con
:
$search_query=mysqli_query($con, $search_sql);