Cannot get result when passing php variable to mysql query
<p>I am trying to pass a part of a file name as a parameter in the my sql query in php. My file name is in the form 
db_feature_T1..iOXXdrXXcAMEra_092521.txt
from which I want the part except the db_feature and .txt i.e.
T1..iOXXdrXXcAMEra_092521</p>

<p>I want the img_id from the database whose img_path=dressimages/T1..iOXXdrXXcAMEra_092521.jpg</p>

<p>My code is as follows.I was able to seperate the file name but I cannot get any result from the database.</p>

<pre><code>            &lt;?php
    include('db.php');

    if ($handle = opendir('C:\Users\adithi.a\Desktop\db_features')) {



        while (false !== ($entry = readdir($handle))) {
            $entry=substr($entry,11,-4); //this seperates the file name db_feature_T1..iOXXdrXXcAMEra_092521.txt to T1..iOXXdrXXcAMEra_092521



            $image_path='dressimages/'.$entry.'.jpg';//I want to pass the img_path as it is saved in the database in the form of dressimages/T1..iOXXdrXXcAMEra_092521.jpg


         $result=  mysql_query("select img_id from tbl_image where img_path='$image_path'") or die("Sorry");
          echo $result;//I dont get anything as output. 
        }

    }

        closedir($handle);
    ?&gt;
</code></pre>

<p>I went to an infinite loop when executing the code above so i tried:</p>

<pre><code>    $image_path='dressimages/'.$entry.'.jpg';//I want to pass the img_path as it is saved in the database in the form of dressimages/T1..iOXXdrXXcAMEra_092521.jpg

        $sql = "select img_id from tbl_image where img_path=".$image_path;
     echo $sql . '&lt;br /&gt;';
        $result=mysql_query("$sql");

       }

            while($data=mysql_fetch_assoc($result))
                  {

                   echo $data["img_id"];
                   }    
</code></pre>

<p>and Now i get the error mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\FashionBonanza\Readfile.php on line 34</p>

<p>Any help</p>
