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
I want the img_id from the database whose img_path=dressimages/T1..iOXXdrXXcAMEra_092521.jpg
My code is as follows.I was able to seperate the file name but I cannot get any result from the database.
<?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);
?>
I went to an infinite loop when executing the code above so i tried:
$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 . '<br />';
$result=mysql_query("$sql");
}
while($data=mysql_fetch_assoc($result))
{
echo $data["img_id"];
}
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
Any help
$result= mysql_query("select img_id from tbl_image where img_path='" . $image_path . "'") or die("Sorry");Just let me know what happens..or die(mysql_error())