Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\laragon\www\newsystem\searchProceeding.php on line 51

Hi, I am trying to do a search web page for the Proceeding title but I have this one problem. I don't know what is the problem, I have looked thoroughly but still don't find it. Please help me. FYI, I don't have any problem with the SQL query on the database.

<?php
include "dbconnect.php";
$keyword=$_GET['keyword'];
$sql="SELECT proceedings.id, proceedings.title, proceedings.author, institutions.name
		FROM proceedings 
		INNER JOIN institutions 
		ON proceedings.institution_code=institutions.institution_code;
	  	WHERE 'title' LIKE '%$keyword%'";
	  	
$result = mysqli_query($conn, $sql);
?>
<table class="table">
	<tr>
		<td>ID</td>
		<td>Title</td>
		<td>Author</td>
		<td>Institution name</td>
	</tr>
<?php
if(mysqli_num_rows($result)>0){
	while ($row=mysqli_fetch_assoc(
		$result)){
		echo "<tr>";
		echo " <td> ".$row['id']."</td>";
		echo "<td> ".$row['title']."</td>";
		echo "<td> ".$row['author']."</td>";
		echo " <td> ".$row['name']."</td>";
		echo "</tr>";
	}
}
?>
</table>

    Welcome to the forums. I edited your post to add some [code]...[/code] tags around your code. Please be sure to use them in the future to aid readability. 😉

    As far as your problem, maybe throw in some temporary debug code to see why the query request is returning FALSE.

    $result = mysqli_query($conn, $sql);
    // debug
    if($result == false) {
      die("<pre>".mysqli_error($conn)."\n$sql</pre>");
    }
    

    Also, this is dangerously susceptible to SQL injection:

    $keyword=$_GET['keyword'];
    $sql="SELECT proceedings.id, proceedings.title, proceedings.author, institutions.name
    		FROM proceedings 
    		INNER JOIN institutions 
    		ON proceedings.institution_code=institutions.institution_code;
    	  	WHERE 'title' LIKE '%$keyword%'";
    	

    You should either be escaping $keyword via mysqli_real_escape_string() or else use a prepared statement with bound parameters.

    NogDog Hiiii thanks for your help! Finally, my problem is solved 😃 Actually I do an error on the SQL syntax and done make a correction Thank you 😄

      Write a Reply...