This script searches a folder and if it finds a .gif file it stores the url of that file in the database. This part works. Now if it finds no .gif in the folder, but a stored url in the database I want it to delete that information form the database. This part doesn't work. Can someone please help me out? The problem starts after the ELSE statement. Many thanks.
<?
$first_name="My Test";
$unwanted=array(0=>"'", 1=>" ");
$clean=str_replace($unwanted,"",$first_name);
//$title=stripslashes($clean);
mysql_connect("localhost","name","pass");
mysql_select_db("db_name");
// set dir name
$dir = "/upload/Bands/$clean";
// open directory
$dir = opendir($dir);
//$fileext = array("gif","jpeg","jpg");
// loop through the directory while reading it's contents
while ($file = readdir($dir)) {
// if the current file in the loop is a pic, then insert into database
if (ereg("gif$", $file)) {
$title = $file;
$fileurl = "http://www.mysite.com/upload/Bands/$clean/$title";
$result = mysql_query("SELECT COUNT(*) FROM artist WHERE pic_link LIKE '$fileurl' and artist_name like '$first_name'");
if (mysql_result($result,0) == 0) {
// not found, so add to table
mysql_query("update artist set pic_link = '$fileurl' WHERE artist_name like '$first_name'");
$pic_array[] = $fileurl;
echo "'$title' added to file<br>";
}
//This is the part that won't work.
else {
// store name of found file
$pic_array[] = $title;
$url="http://www.mysite.com/upload/Bands/$clean/";
}
}
// now delete the ones that weren't found
$piclist = "'" . join("','", $url,$pic_array) . "'";
$res = mysql_query ("SELECT pic_link FROM artist WHERE pick_link NOT IN ($piclist) AND artist_name LIKE '$first_name'");
while ($r = mysql_fetch_row($res)) {
}
mysql_query ("DELETE pic_link FROM artist WHERE pic_link NOT IN ($piclist) AND artist_name LIKE '$first_name'");
}
?>