MySQL error saying query is empty. I can't see this.
Posted: Fri Jun 13, 2008 12:54 am
The code below stops at 'Opening Directory', with the error:
I don't see how this is even possible, I've checked and rechecked all my references, none of the query strings could possibly be empty! Also in between the two reference points (echoing of Opening Directory and Opening $file) there aren't any SQL Queries! Am I missing something?Your Query:
Error: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Code: Select all
<?php
include_once('lib.php');
include_once('gallerylib.php');
mysqlConnect();
$query = "SELECT ID FROM galleryindex ORDER BY ID DESC LIMIT 1";
$result = mysqlQuery($query);
$row = mysql_fetch_assoc($result);
$AID = $row['ID'] + 1;
$path = 'filedump/';
$dir = opendir($path);
$firstimg = true;
$width = 800;
$height = 800;
$i=1;
$i=1;
while(($file = readdir($dir)) !== false)
{
$filetype = filetype($path . $file);
if($filetype == 'dir' && !($file == '.' || $file == '..' || substr($file,0,4) == 'DONE'))
{
echo $file . " found.\n";
//check new gallery
$query2 = 'SELECT ID FROM galleryindex WHERE name=\''.addslashes($file).'\'';
$result2 = mysqlQuery($query2);
if(mysql_num_rows($result2) == 1)
{
//existing
echo "This gallery exists, appending photos...\n";
$row2=mysql_fetch_assoc($result2);
$AID = $row2['ID'];
}else{
//new
$query1 = "INSERT INTO galleryindex (ID,name) VALUES ($AID,'" . addslashes($file) . "')";
echo $query1;
$result1 = mysqlQuery($query1);
echo "Database updated.\n";
}
$dir2 = opendir($path . $file);
echo "Opening Directory\n";
while(($file2 = readdir($dir2)) !== false)
{
$i++;
$qID = time() . $i;
if(substr($file2,-3) == 'jpg' || substr($file2,-4) == 'jpeg')
{
echo 'Opening '.$file2."\n";
if($firstimg)
{
//set cover
echo 'Setting Cover'."\n";
$firstimg=false;
$query3 = "UPDATE galleryindex SET cover=$qID WHERE ID=$AID";
echo $query3;
$result3 = mysqlQuery($query3);
echo "Cover set to: ";
}
list($width_orig, $height_orig) = getimagesize($path . $file . '/' . $file2);
if($width_orig > $width || $height_orig > $height)
{
//resize here
$image_p = resizeImage($width_orig,$height_orig,$width,$height,$path . $file . '/' . $file2);
imagejpeg($image_p, 'gallery/images/' . $qID . '.jpg', 100);
$image_p = resizeImage($width_orig,$height_orig,100,150,$path . $file . '/' . $file2);
imagejpeg($image_p,'gallery/images/' . $qID . 'thumb.jpg', 100);
echo $file2 . " added and resized.\n";
//resizing done
}else{
//original does not need resizing
$image_p = resizeImage($width_orig,$height_orig,100,150,$path . $file . '/' . $file2);
imagejpeg($image_p,'gallery/images/' . $qID . 'thumb.jpg', 100);
move_uploaded_file($path . $file . '/' . $file2, 'gallery/images/' . $qID . ".jpg");
echo $file2 . " added but not resized.\n";
//all done
}
//echo "Temp file " . $file2 . " deleted. \n";
$values .= "('$AID','$qID'),";
}
}
closedir($dir2);
}
}
closedir($dir);
$query = "INSERT INTO gallerycontents (AID,path) VALUES " . substr($values,0,-1);
$result = mysqlQuery($query);
galleryrss($AID);
?>