4images Forum & Community

4images Issues / Ausgaben => Discussion & Troubleshooting => Topic started by: Eagle Eye on March 19, 2009, 08:55:58 PM

Title: DB Error: Bad SQL Query
Post by: Eagle Eye on March 19, 2009, 08:55:58 PM
I am getting this error each time my site loads... once we navigate from homepage to other page and return to homepage, this error is gone. Looks like something to do with sessions? Is this related to one of V@no's MOD: http://www.4homepages.de/forum/index.php?topic=3842.msg15861#msg15861 (http://www.4homepages.de/forum/index.php?topic=3842.msg15861#msg15861) ???

Code: [Select]
DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name, u.user_name FROM 4images_images i, 4images_categories c LEFT JOIN 4images_users u ON (u.user_id = i.user_id) WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (0, 106, 60, 64, 56, 50, 62, 135, 146, 58, 160, 91, 192, 30, 66, 118, 16, 188, 114, 186, 197, 15, 138, 226, 227, 41, 111, 42, 241, 116, 77, 4, 39, 38, 147, 235, 130, 157, 131, 83, 29, 32, 59, 149, 198, 191, 129, 26, 177, 63, 210, 187, 31, 94, 223, 93, 14, 40, 37, 84, 218, 238, 150, 113, 45, 20, 153, 206, 169, 57, 137, 215, 132, 61, 108, 209, 158, 46, 110, 151, 178, 133, 219, 47, 239, 171, 78, 224, 33, 112, 170, 179, 180, 181, 36, 96, 3, 102, 76, 103, 44, 2, 101, 81, 104, 100, 105, 17, 82, 142, 71, 139, 141, 217, 243, 172, 70, 204, 199, 174, 167, 90, 109, 173, 89, 203, 202, 5, 68, 244, 52, 21, 115, 140, 136, 8, 182, 155, 194, 53, 144, 193, 65, 87, 216, 69, 55, 9, 225, 125, 161, 230, 23, 19, 48, 43, 22, 196, 208, 73, 220, 200, 134, 185, 232, 229, 49, 119, 166, 67, 213, 165, 145, 156, 10, 214, 72, 128, 201, 163, 175, 34, 13, 168, 176, 195, 233, 95, 240, 162, 143, 228, 121, 24, 25, 189, 205, 80, 231, 127, 234, 79, 11, 12, 51, 148, 184, 211, 98, 190, 28, 154, 212, 122, 6, 99, 74, 221, 126, 207, 88, 246, 245, 123, 242, 27, 35, 222, 117, 159, 86, 152, 107, 18, 97, 54, 85, 120, 237, 236, 164) AND i.image_votes > 25 ORDER BY i.image_rating DESC, i.image_votes DESC
Unknown column 'i.user_id' in 'on clause'

DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name, u.user_name FROM 4images_images i, 4images_categories c LEFT JOIN 4images_users u ON (u.user_id = i.user_id) WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (0, 106, 60, 64, 56, 50, 62, 135, 146, 58, 160, 91, 192, 30, 66, 118, 16, 188, 114, 186, 197, 15, 138, 226, 227, 41, 111, 42, 241, 116, 77, 4, 39, 38, 147, 235, 130, 157, 131, 83, 29, 32, 59, 149, 198, 191, 129, 26, 177, 63, 210, 187, 31, 94, 223, 93, 14, 40, 37, 84, 218, 238, 150, 113, 45, 20, 153, 206, 169, 57, 137, 215, 132, 61, 108, 209, 158, 46, 110, 151, 178, 133, 219, 47, 239, 171, 78, 224, 33, 112, 170, 179, 180, 181, 36, 96, 3, 102, 76, 103, 44, 2, 101, 81, 104, 100, 105, 17, 82, 142, 71, 139, 141, 217, 243, 172, 70, 204, 199, 174, 167, 90, 109, 173, 89, 203, 202, 5, 68, 244, 52, 21, 115, 140, 136, 8, 182, 155, 194, 53, 144, 193, 65, 87, 216, 69, 55, 9, 225, 125, 161, 230, 23, 19, 48, 43, 22, 196, 208, 73, 220, 200, 134, 185, 232, 229, 49, 119, 166, 67, 213, 165, 145, 156, 10, 214, 72, 128, 201, 163, 175, 34, 13, 168, 176, 195, 233, 95, 240, 162, 143, 228, 121, 24, 25, 189, 205, 80, 231, 127, 234, 79, 11, 12, 51, 148, 184, 211, 98, 190, 28, 154, 212, 122, 6, 99, 74, 221, 126, 207, 88, 246, 245, 123, 242, 27, 35, 222, 117, 159, 86, 152, 107, 18, 97, 54, 85, 120, 237, 236, 164) ORDER BY i.image_votes DESC, i.image_rating DESC
Unknown column 'i.user_id' in 'on clause'

DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name, u.user_name FROM 4images_images i, 4images_categories c LEFT JOIN 4images_users u ON (u.user_id = i.user_id) WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (0, 106, 60, 64, 56, 50, 62, 135, 146, 58, 160, 91, 192, 30, 66, 118, 16, 188, 114, 186, 197, 15, 138, 226, 227, 41, 111, 42, 241, 116, 77, 4, 39, 38, 147, 235, 130, 157, 131, 83, 29, 32, 59, 149, 198, 191, 129, 26, 177, 63, 210, 187, 31, 94, 223, 93, 14, 40, 37, 84, 218, 238, 150, 113, 45, 20, 153, 206, 169, 57, 137, 215, 132, 61, 108, 209, 158, 46, 110, 151, 178, 133, 219, 47, 239, 171, 78, 224, 33, 112, 170, 179, 180, 181, 36, 96, 3, 102, 76, 103, 44, 2, 101, 81, 104, 100, 105, 17, 82, 142, 71, 139, 141, 217, 243, 172, 70, 204, 199, 174, 167, 90, 109, 173, 89, 203, 202, 5, 68, 244, 52, 21, 115, 140, 136, 8, 182, 155, 194, 53, 144, 193, 65, 87, 216, 69, 55, 9, 225, 125, 161, 230, 23, 19, 48, 43, 22, 196, 208, 73, 220, 200, 134, 185, 232, 229, 49, 119, 166, 67, 213, 165, 145, 156, 10, 214, 72, 128, 201, 163, 175, 34, 13, 168, 176, 195, 233, 95, 240, 162, 143, 228, 121, 24, 25, 189, 205, 80, 231, 127, 234, 79, 11, 12, 51, 148, 184, 211, 98, 190, 28, 154, 212, 122, 6, 99, 74, 221, 126, 207, 88, 246, 245, 123, 242, 27, 35, 222, 117, 159, 86, 152, 107, 18, 97, 54, 85, 120, 237, 236, 164) ORDER BY i.image_hits DESC, i.image_name ASC
Unknown column 'i.user_id' in 'on clause'

DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name, u.user_name FROM 4images_images i, 4images_categories c LEFT JOIN 4images_users u ON (u.user_id = i.user_id) WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (0, 106, 60, 64, 56, 50, 62, 135, 146, 58, 160, 91, 192, 30, 66, 118, 16, 188, 114, 186, 197, 15, 138, 226, 227, 41, 111, 42, 241, 116, 77, 4, 39, 38, 147, 235, 130, 157, 131, 83, 29, 32, 59, 149, 198, 191, 129, 26, 177, 63, 210, 187, 31, 94, 223, 93, 14, 40, 37, 84, 218, 238, 150, 113, 45, 20, 153, 206, 169, 57, 137, 215, 132, 61, 108, 209, 158, 46, 110, 151, 178, 133, 219, 47, 239, 171, 78, 224, 33, 112, 170, 179, 180, 181, 36, 96, 3, 102, 76, 103, 44, 2, 101, 81, 104, 100, 105, 17, 82, 142, 71, 139, 141, 217, 243, 172, 70, 204, 199, 174, 167, 90, 109, 173, 89, 203, 202, 5, 68, 244, 52, 21, 115, 140, 136, 8, 182, 155, 194, 53, 144, 193, 65, 87, 216, 69, 55, 9, 225, 125, 161, 230, 23, 19, 48, 43, 22, 196, 208, 73, 220, 200, 134, 185, 232, 229, 49, 119, 166, 67, 213, 165, 145, 156, 10, 214, 72, 128, 201, 163, 175, 34, 13, 168, 176, 195, 233, 95, 240, 162, 143, 228, 121, 24, 25, 189, 205, 80, 231, 127, 234, 79, 11, 12, 51, 148, 184, 211, 98, 190, 28, 154, 212, 122, 6, 99, 74, 221, 126, 207, 88, 246, 245, 123, 242, 27, 35, 222, 117, 159, 86, 152, 107, 18, 97, 54, 85, 120, 237, 236, 164) ORDER BY i.image_downloads DESC, i.image_name ASC
Title: Re: DB Error: Bad SQL Query
Post by: Eagle Eye on March 19, 2009, 09:07:37 PM
V@no, can this be the possible solution? http://www.4homepages.de/forum/index.php?topic=10184.15 (http://www.4homepages.de/forum/index.php?topic=10184.15)
i am running  MySQL version  5.0.67-community-log.
Title: Re: DB Error: Bad SQL Query
Post by: V@nо on March 19, 2009, 10:24:06 PM
yes that's the sollution
Title: Re: DB Error: Bad SQL Query
Post by: Eagle Eye on April 10, 2009, 02:05:44 AM
Finally i got down to fix this error... interestingly all what u have instructed to replace are already in place... meaning, the mods i used and the script is update.. but the error still continues...

Can i PM u my error log for 4images?
Title: Re: DB Error: Bad SQL Query
Post by: V@no on April 10, 2009, 02:47:33 AM
If you see the same errors as the above, then a MySQL query somewhere in your 4images is not "up-to-date".
Title: Re: DB Error: Bad SQL Query
Post by: Eagle Eye on April 10, 2009, 04:23:59 AM
Actually i do not see the above error... i just saw it once...

Usually i always get the following:
Code: [Select]
An unexpected error occured. Please try again later.

An unexpected error occured. Please try again later.

An unexpected error occured. Please try again later.

An unexpected error occured. Please try again later.

An unexpected error occured. Please try again later.

in the error log it is showing some info which i am not fully understanding.. if u can have a look then u caould guide me to which file could possible have this problem....
I can PM it to u if u wish... its a small one.. about 5-6KB (just cleaned up the old log)
Title: Re: DB Error: Bad SQL Query
Post by: V@no on April 10, 2009, 04:27:15 AM
An unexpected error occured. Please try again later (http://www.4homepages.de/forum/index.php?topic=24177.0)
Title: Re: DB Error: Bad SQL Query
Post by: Eagle Eye on April 10, 2009, 05:39:50 AM
Ah, yes.. now i see the error.. its the same error, i had posted in the beginning of this topic...i tried to find the codes as u instructed, but they all seems to be in place.... i know its somewhere there but just cannot find it...

looking into my error log i see the following each time i got "An unexpected error occured. Please try again later"

Code: [Select]
Cannot modify header information - headers already sent by (output started at /home/xxxxxxxxxx/public_html/includes/db_mysql.php:192) in /home/xxxxxxxxxx/public_html/includes/sessions.php on line 101
in file db_mysql.php around line 192 i see:

from line 170-220
Code: [Select]


  function fetch_array($query_id = -1, $assoc = 0) {

    if ($query_id != -1) {

      $this->query_id = $query_id;

    }

    if ($this->query_id) {

      return ($assoc) ? mysql_fetch_assoc($this->query_id) : mysql_fetch_array($this->query_id);

    }

  }



  function free_result($query_id = -1) {

    if ($query_id != -1) {

      $this->query_id = $query_id;

    }

    return @mysql_free_result($this->query_id);

  }



  function query_firstrow($query = "") {

    if ($query != "") {

      $this->query($query);

    }

    $result = $this->fetch_array($this->query_id);

    $this->free_result();

    return $result;

  }



in file sessions.php around line 90 to 120

Code: [Select]
    //@ini_set('session.cookie_lifetime', $this->session_timeout);

    session_name(urlencode(SESSION_NAME));
    @session_start();

    $this->demand_session();
  }

  function set_cookie_data($name, $value, $permanent = 1) {
    $cookie_expire = ($permanent) ? $this->current_time + 60 * 60 * 24 * 365 : 0;
    $cookie_name = COOKIE_NAME.$name;
    setcookie($cookie_name, $value, $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
    $HTTP_COOKIE_VARS[$cookie_name] = $value;
  }

  function read_cookie_data($name) {
    global $HTTP_COOKIE_VARS;
    $cookie_name = COOKIE_NAME.$name;
    return (isset($HTTP_COOKIE_VARS[$cookie_name])) ? $HTTP_COOKIE_VARS[$cookie_name] : false;
  }

  function get_session_id() {
    if (SID == '') {
      $this->mode = "cookie";
    }

    if (preg_match('/[^a-z0-9]+/i', session_id())) {
      @session_regenerate_id();
    }

    $this->session_id = session_id();

 :?

when i went to postcards.php i got another error in the log...

Code: [Select]
include(./global.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/xxxxxxxxxx/public_html/postcards.php on line 27
[09-Apr-2009 18:23:26] PHP Warning:  include(./global.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/xxxxxxxxxx/public_html/postcards.php on line 27
[09-Apr-2009 18:23:26] PHP Warning:  include() [<a href='function.include'>function.include</a>]: Failed opening './global.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxxxxxxxxx/public_html/postcards.php on line 27
[09-Apr-2009 18:23:26] PHP Fatal error:  Call to a member function query() on a non-object in /home/xxxxxxxxxx/public_html/includes/sessions.php on line 226

everything seems to be working with the ecard function... can this be due to some file being included somewhere in the postcards template using <?php include(.......); ?> i checked the postcard templates and did not find anything there....
Title: Re: DB Error: Bad SQL Query
Post by: V@no on April 10, 2009, 02:12:37 PM
First of all, check out this topic: Unknown column 'i.user_id' in 'on clause' (http://www.4homepages.de/forum/index.php?topic=22668.0)
This should help you find the bad query (for some reason I was convinced you were referring to it before).

As of second error, its probably somewhere in template, because if 4images fails include it's global.php it would died immediately, aka nothing would work. I'd suggest find a text editor that can batch search in files and search for global.php If it finds it in template files, then it might be it.