I have tried changing the code I poster earlier and have come up with this new one:
PHP Code:
<?
$host="******"; // Host name
$username="******"; // Mysql username
$password="******"; // Mysql password
$db_name="******"; // Database name
$tbl_name="******"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
// Define the full path to the folder whose contents you want to list
$path = ".";
//File Types allowed
$pattern="\.(jpg|jpeg)$";
// Open the directory
$dir_handle = @opendir($path) or die("Error opening $path");
// Loop through the files and filter out no jpgs
while(false !== ($file = readdir($dir_handle))){
if(eregi($pattern, $file)){
$query = "SELECT filename FROM $tbl_name";
$result = mysql_query($query) or die('Error, query failed one');
while($rows=mysql_fetch_array($result)){
if ($row['filename']=="$file") {
echo "<p>$file already exists in database</p>"; }
else {
//Insert data into database
$sql="INSERT INTO $tbl_name (filename, category, large, thumb)VALUES('$file', 'landscape' 'http://www.calumogg.co.uk/landscapes/large/$file', 'http://www.calumogg.co.uk/landscapes/thumbs/$file')";
$result = mysql_query($query) or die('Error, query failed two');
echo "<p>$file has been added to the database</p>"; }
}}}
// Close
closedir($dir_handle);
?>
And this still isnt working. Any help would be much appreciated
Bookmarks