I get an error "mysqli_query() expects parameter 2 to be string" when I trying to fetch data from database using mysquli.
my code is:
$query = "SELECT * FROM table_name WHERE column = '" . $query . "'";
// Preparation
$query = $conn->prepare($query);
// Get result;
$result = mysqli_query($conn, $query);
if ($result->num_rows > 0) {
$slugResult = $result->fetch_all();
// My PHP code here
}
Please give me a solution.
mysqli_query(Parameter 1, Parameter 2);
In mysqli_query() parameter 2 shuold be string.
Problem here:
Your var $query does not contain a string.
Solution:
Store in your var $query a string like:
$query = "SELECT * FROM table_name WHERE column = '" . $query . "'";
then use var $query to fetch result,
Your code should be like the following:
If you still have a question about this, submit it in our Q&A community - Ask Question