-1
I’m having the following mistake:
Object of class mysqli could not be converted to string.
PHP code:
<?php
include("config.php");
$query = $_GET['query'];
$min_length = 3;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysqli_real_escape_string($conn,$query);
$row_results = mysqli_query($conn,"SELECT * FROM books
WHERE (`Title` LIKE '%".$query.$conn."%') OR (`text` LIKE '%".$query.$conn."%')") or die(mysqli_error());
if(mysqli_num_rows($row_results) > 0){
while($results = mysqli_fetch_array($row_results)){
echo "<p><h3>".$results['title']."</h3>".$results['text']."</p>";
}
}
else{
echo "No results";
}
}
else{
echo "Minimum length is ".$min_length;
}
?>
I don’t understand what’s missing
What would those be
$query.$conn
within the query?– Woss
mysqli requires two parameters, in this case the first one is $Conn the connection to the database and the second one is SELECT statement
– Diana Madeira
I edited the answer, now you have the whole code
– Diana Madeira
Yes, but it makes no sense to have the object of connection to the database in the middle of the
select
. Try to remove$conn
where is$query.$conn
.– Woss
"SELECT * FROM books WHERE Title LIKE '%".$query."%' OR text LIKE '%".$query."%'"
– Woss
if I remove $Conn, error, mysqli says it needs 2 parameters
– Diana Madeira
Which
$conn
you took?– Woss
what’s behind the SELECT
– Diana Madeira
See my comment above. I passed exactly what is the
$conn
that you should withdraw. It should not be WITHIN the instructionSELECT
.– Woss
Let’s go continue this discussion in chat.
– Woss