gildas-Milandou Posted June 1, 2023 Share Posted June 1, 2023 Here is a message error that I got after trying to get a data from a database by pressing search button: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given inC:\xampp\htdocs\E-commerce-website\functions\common_function.phpon line237 Here is the code it is a function call search_product: function search_product(){ global $con; if(isset($_GET['search_data_product'])) { $search_data_value=$_GET['search_data']; $search_query="select * from `products` where product_keywords like `%search_data_value%`"; $result_query=mysqli_query($con,$search_query); while($row=mysqli_fetch_assoc($result_query)) { $product_id=$row['product_id']; $product_title=$row['product_title']; $product_description=$row['product_description']; $product_image1=$row['product_image1']; $product_image2=$row['product_image2']; $product_image3=$row['product_image3']; $product_price =$row['product_price']; $category_id=$row['category_id']; $brand_id=$row['brand_id']; echo " " Quote Link to comment https://forums.phpfreaks.com/topic/316932-hi-have-a-qustion-please/ Share on other sites More sharing options...
Barand Posted June 1, 2023 Share Posted June 1, 2023 If $result_query is boolean, then the query failed and returned "false". For future reference, call this line of code before you connect to your database so any mysql errors get reported... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); Quote Link to comment https://forums.phpfreaks.com/topic/316932-hi-have-a-qustion-please/#findComment-1609343 Share on other sites More sharing options...
ginerjm Posted June 1, 2023 Share Posted June 1, 2023 You probably need a dollar sign in this line: product_keywords like `%search_data_value%`"; if you are trying to match the contents of that variable. And that is why the query failed to execute Quote Link to comment https://forums.phpfreaks.com/topic/316932-hi-have-a-qustion-please/#findComment-1609344 Share on other sites More sharing options...
Solution Barand Posted June 1, 2023 Solution Share Posted June 1, 2023 I didn't notice before (because you didn't use a code block) but you have used backticks around `%search_data_value%`. Those will force SQL to treat it as a column name. Use single quotes around strings. 1 Quote Link to comment https://forums.phpfreaks.com/topic/316932-hi-have-a-qustion-please/#findComment-1609345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.