Page 1 of 2

Error

Posted: Thu Jul 10, 2008 11:04 am
by Aishah
Hello,

There is somenting very wrong with my forum.

I was trying to make a forum a subforum of another and this came up:

Code: Select all

General Error
SQL ERROR [ mysql4 ]

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 'AND right_id >' at line 4 [1064]

SQL

UPDATE phpbb_forums SET right_id = right_id - 2, forum_parents = '' WHERE left_id < AND right_id > 

BACKTRACE


FILE: includes/db/mysql.php
LINE: 158
CALL: dbal_mysql->sql_error()

FILE: includes/acp/acp_forums.php
LINE: 1281
CALL: dbal_mysql->sql_query()

FILE: includes/acp/acp_forums.php
LINE: 1209
CALL: acp_forums->move_forum()

FILE: includes/acp/acp_forums.php
LINE: 176
CALL: acp_forums->update_forum_data()

FILE: includes/functions_module.php
LINE: 471
CALL: acp_forums->main()

FILE: adm/index.php
LINE: 74
CALL: p_master->load_active()
Also, when I'm trying to manage the forums from the admin cp, they are all jumbling up and making their own parent categroies etc. when I'm trying to change them.

Thanks, Kind regards.

Re: Error

Posted: Thu Jul 10, 2008 11:10 am
by jimdunn
The problems you are describing look a bit like they could be caused by some damage to the forum "tree" in your forums table. I'm not saying it is definitely your issue, but the symptoms look similar.

There have been a couple of recent topics where this sort of thing has been solved by running a script to rebuild that tree.

Before I give you a link to the script, I'm going to stress that you should backup your database before attempting this solution. There is a possibility that the script could make your situation worse, so you need a database backup to restore to if that happens.

If you don't know how to backup your database PLEASE post back and ask for instructions to do that before running this script.

Note that I am talking about backing up your database - not your forum files - the 2 things are distinctly different.

That being said, here is a link to the script, and instructions to run it:
http://www.phpbb.com/community/viewtopi ... 5#p5975935

Re: Error

Posted: Thu Jul 10, 2008 11:15 am
by Aishah
How do I backup my database?

Re: Error

Posted: Thu Jul 10, 2008 11:22 am
by jimdunn
2) Exporting Database.
2.a. Load into phpMyAdmin.
2.b. Select your database.
2.c. Click the tab "export".
2.d. Once on the "export page", you will see numerous options in different boxes. Make sure that:
- All the tables are selected if not, click "Select All"
- Make sure the output is SQL, if not click the radio button SQL
- In the "Structure" box, check the box next to "Add DROP TABLE"

Download:
- Check the box "Save as file"
- Choose your compression, none
- Click Go.
- You will get a download file, save to your desktop (Or chosen destination)
Taken from:
http://www.phpbb.com/kb/article/moving- ... phpmyadmin

Re: Error

Posted: Thu Jul 10, 2008 11:30 am
by Aishah
Hello,

Is there anyway to know which one of the database names is the one for my current forum? because I have two for the forum and one belongs to the old forum I had (we think) which still remains.

Kind regards.

Re: Error

Posted: Thu Jul 10, 2008 11:33 am
by jimdunn
Yes

Look in the config.php file in the folder on your server which contains the forum in question.

Code: Select all

$dbname =

Re: Error

Posted: Thu Jul 10, 2008 11:36 am
by Aishah
Thank you. So I can delete the other one which I don't use?

Re: Error

Posted: Thu Jul 10, 2008 11:38 am
by Aishah
Now that I've backed it up, I name the file fixtree.php ?

Re: Error

Posted: Thu Jul 10, 2008 11:39 am
by jimdunn
Aishah wrote:Thank you. So I can delete the other one which I don't use?
Well, yes if you don't use it, you can.

But be very certain it is an unused database before you do that - if you're not sure just leave it - it won't do any harm.

Because of the type of person I am I'd probably back it up first if I was going to delete it - you never know ;)

Re: Error

Posted: Thu Jul 10, 2008 11:43 am
by Aishah
Thanks.

Re: Error

Posted: Thu Jul 10, 2008 11:44 am
by jimdunn
Aishah wrote:Now that I've backed it up, I name the file fixtree.php ?
What file ?

The backup file you name anything you like - maybe backup.sql
You only need it if you need to restore the database.

fixtree.php is the script I linked you to.
You copy that code from the linked post into a new file and call it fixtree.php

It might be worth taking a little time to read the instructions again if you're confused :)

Re: Error

Posted: Thu Jul 10, 2008 11:46 am
by Aishah

Code: Select all

<?php
/**
*
* @package phpBB3
* @version $Id: index.php,v 1.176 2007/10/05 14:30:06 acydburn Exp $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');

recalc_btree('forum_id' , FORUMS_TABLE);
echo "Done";

function recalc_btree($sql_id, $sql_table, $module_class = '')
{
    global $db;

    if (!$sql_id || !$sql_table)
    {
        return;
    }

    $sql_where = ($module_class) ? " WHERE module_class = '" . $db->sql_escape($module_class) . "'" : '';

    // Reset to minimum possible left and right id
    $sql = "SELECT MIN(left_id) as min_left_id, MIN(right_id) as min_right_id
        FROM $sql_table
        $sql_where";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);

    $substract = (int) (min($row['min_left_id'], $row['min_right_id']) - 1);

    if ($substract > 0)
    {
        $sql = "UPDATE $sql_table
            SET left_id = left_id - $substract, right_id = right_id - $substract
            $sql_where";
        $db->sql_query($sql);
    }

    $sql = "SELECT $sql_id, parent_id, left_id, right_id
        FROM $sql_table
        $sql_where
        ORDER BY left_id ASC, parent_id ASC, $sql_id ASC";
    $f_result = $db->sql_query($sql);

    while ($item_data = $db->sql_fetchrow($f_result))
    {
        if ($item_data['parent_id'])
        {
            $sql = "SELECT left_id, right_id
                FROM $sql_table
                $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . "
                    $sql_id = {$item_data['parent_id']}";
            $result = $db->sql_query($sql);

            if (!$row = $db->sql_fetchrow($result))
            {
                $sql = "UPDATE $sql_table SET parent_id = 0 WHERE $sql_id = " . $item_data[$sql_id];
                $db->sql_query($sql);

                continue;    
            }
            $db->sql_freeresult($result);

            $sql = "UPDATE $sql_table
                SET left_id = left_id + 2, right_id = right_id + 2
                $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . "
                    left_id > {$row['right_id']}";
            $db->sql_query($sql);

            $sql = "UPDATE $sql_table
                SET right_id = right_id + 2
                $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . "
                    {$row['left_id']} BETWEEN left_id AND right_id";
            $db->sql_query($sql);

            $item_data['left_id'] = $row['right_id'];
            $item_data['right_id'] = $row['right_id'] + 1;
        }
        else
        {
            $sql = "SELECT MAX(right_id) AS right_id
                FROM $sql_table
                $sql_where";
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);

            $item_data['left_id'] = $row['right_id'] + 1;
            $item_data['right_id'] = $row['right_id'] + 2;
        }
    
        $sql = "UPDATE $sql_table
            SET left_id = {$item_data['left_id']}, right_id = {$item_data['right_id']}
            WHERE $sql_id = " . $item_data[$sql_id];
        $db->sql_query($sql);
    }
    $db->sql_freeresult($f_result);
}

?>
This is the script I need to call fixtree.php ?

Re: Error

Posted: Thu Jul 10, 2008 11:48 am
by jimdunn
Yes - if you copied that from the linked post.

(I haven't checked it's all there in what you posted :) )

Re: Error

Posted: Thu Jul 10, 2008 11:49 am
by Aishah
Done.

Re: Error

Posted: Thu Jul 10, 2008 11:49 am
by Aishah
Thank you. I deleted the fixtree file. Have a nice day.