Jump to content

Hi, have a qustion please


Go to solution Solved by Barand,

Recommended Posts

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 "   "          

Link to comment
https://forums.phpfreaks.com/topic/316932-hi-have-a-qustion-please/
Share on other sites

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);

 

  • Solution

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.

  • Haha 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.