coppermine-gallery.com/forum

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: steveclv on April 20, 2014, 10:39:05 PM

Title: Critical database error after search
Post by: steveclv on April 20, 2014, 10:39:05 PM
If I search my gallery http://www.picturethis.com.mt/gallery/ (http://www.picturethis.com.mt/gallery/) and then click on one of the results (try using DOME as the search term) I then get a critical database error.

I enabled debug mode and this is what I get - can anyone help please?

While executing query 'SELECT COUNT(*) FROM cpg15x_pictures AS p
                LEFT JOIN `picture_db`.cpg15x_users AS u ON p.owner_id = u.user_id
                WHERE ((p.title LIKE '%dome%')) AND approved = 'YES'
                AND (title < 'Mellieha Church Dome and Bell Tower' OR title = 'Mellieha Church Dome and Bell Tower' AND pid < 446)' in include/search.inc.php on line 255

mySQL error: Column 'title' in where clause is ambiguous

USER:
------------------
Array
(
    [ID] => f8bc9479b69450327e43736e3e494227
    [am] => 1
    [lang] => english
    [liv] => Array
        (
           
Title: Re: Critical database error after search
Post by: steveclv on April 20, 2014, 10:46:51 PM
I did find another thread that talked about a plugin adding a column called 'Title' to the user table and suggesting a fix to search_inc.php

I checked the php code and the 'fix' was already in there but I also checked the user table and there is a column in there called 'title' - I renamed it to 'title2' and it fixed the problem but how can I fix the problem correctly in the code without changing the database as I don't know what other errors may now occur.
Title: Re: Critical database error after search
Post by: gmc on April 21, 2014, 03:18:12 AM
Since both pictures (cpg15x_pictures AS p) from base code and users (cpg15x_users AS u) from a mod/plugin have a field named 'title' - it needs to be qualified as p.title in the sql being issued to tell MySQL it is referring the the title in the pictures title...
That qualification comes from the variable '$FORBIDDEN_SET' which is used in many queries - and they may not all define 'p' as pictures...

I'd need to look closer at the other thread and the code (search seems to be having some issues at the moment...)
I'll take a look tomorrow unless someone else gets to it first.

(The change you made renaming title to title2 in users table won't affect base code - but will affect whatever mod is expecting it to be there.)
Title: Re: Critical database error after search
Post by: Αndré on April 22, 2014, 03:12:17 PM
The following mod is not tested, but should work. Open include/search.inc.php, find
$sort_order = "$criteria $direction '$criteria_pid' OR $criteria = '$criteria_pid' AND pid < $pid";
and above, add
if ($criteria == 'title') {
    $criteria = 'p.title';
}
Title: Re: Critical database error after search
Post by: steveclv on April 22, 2014, 10:20:37 PM
Thanks!!
Title: Re: Critical database error after search
Post by: Αndré on April 23, 2014, 08:50:52 AM
Marking thread as solved. Next time, please do this yourself as explained in the board rules:

Quote from: Joachim Müller on September 28, 2008, 12:46:26 PM
Resolve your threads
If you have found an answer to your question, resolve your thread. Don't just post "I have found the answer", but tell others what you actually did to solve your issues. Posting a link to the page where you found the answer might help. Describing what you did might help as well. Finally, you can tag your thread as "solved" by clicking on the "Topic Solved" button on the bar at the left hand side at the bottom of your thread.