Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MyBB SQL Error 1064
#1
So I'm trying to use a pagination code I found and this is what I get:

Code:
MyBB has experienced an internal SQL error and cannot continue.

SQL 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
Query:
SELECT * FROM mybb_threads WHERE fid='2' ORDER BY tid DESC LIMIT

I am using this:

PHP Code:
<?php

    
// START VARS
 
       $fid 2// FORUM ID
 
          $perpage 5// ITEMS PER PAGE
 
         $forumpath ''// FORUM PATH
 
       $filename ''// NAME OF THE FILE
 
   // END VARS

 
   // START DONT TOUCH STUFF
 
          chdir('$forumpath');
 
           define("IN_MYBB"1);
 
           require('/global.php');
 
           require_once MYBB_ROOT."inc/class_parser.php";
 
           require_once MYBB_ROOT."inc/functions_post.php";
 
           require_once MYBB_ROOT."inc/functions_user.php";
 
           $parser = new postParser;
 
          chdir('');
 
   // END DONT TOUCH STUFF
 
       
    
// INCOMING
 
   $page intval($mybb->input['page']);

 
   // COUNT RECORDS
 
   $query $db->simple_select('threads''COUNT(*) AS threads'"fid='{$fid}'");
 
   $num $db->fetch_field($query"threads");

 
   // PAGING ( MULTI )
 
   if($page)
 
   {
 
       $start = ($page 1) * $perpage;
 
   }
 
   else
    
{
 
       $start 0;
 
       $page 1;
 
   }
 
   $multipage multipage($num$perpage$page$filename."?");

 
   // GET THREADS
 
   $query $db->simple_select('threads''*'"fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");
 
   if($db->num_rows($query) > 0)
 
   {
 
       while($row $db->fetch_array($query))
 
       {
 
           $query2 $db->simple_select('posts''*'"pid='{$row['firstpost']}'");
 
           $row2 $db->fetch_array($query2);
 
           
            $date 
my_date($mybb->settings['dateformat'], $row2['dateline'], ""1);
 
           $time my_date($mybb->settings['timeformat'], $row2['dateline'], ""1);

 
           $options = array(
 
                       "allow_html" => 1,
 
           "allow_mycode" => 1,
 
           "allow_smilies" => 1,
 
           "allow_imgcode" => 1,
 
           "allow_videocode" => 1,
 
           "filter_badwords" => 1
                            
);
 
           $message $parser->parse_message($row2['message'], $options);
 
           
            echo
("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
                Posted: 
{$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br />");
 
           echo("{$message}<br /><br />");
 
           echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br />");
 
       }
 
   }
 
   else
    
{
 
       echo 'Nothing to display.';
 
   }

?>

Anybody got any suggestions?
Reply
#2
For starters, you never define $limit but try to use it in the query. Also chdir('$forumpath') will try to change directories to a directory literally called '$forumpath' which isn't the goal. Use double quotes around variables so that they're interpreted as variables, anything in single quotes gets treated as a string automatically.
Code:
chdir($forumpath);

$forumpath and $filename you've left blank. They need to be set for this to work.

Could be more wrong with it but these need to be fixed first for sure. Also, what third party software are you trying to use this with?

Where did you find this if you don't mind me asking?
My Plugins: [1.8]|[1.6]

** Selling custom plugin that enables Bitcoin payments. PM me if interested in purchasing! **
Reply
#3
Thanks for the response! Could you expand on the $limit a bit further?

Oh don't worry, the code I displayed in my first post is just to show the code. I took out all the paths directed to my actual site including the $forumpath and $filename so I know about all that. I should've probably cleared that up in the first post, but thank you though! I'll try the quotes though.

I'm just using the code I found in this section that integrates your myBB forum threads to your website here: https://community.mybb.com/thread-22068.html the pagination code is at the bottom of page 1.
Reply
#4
I gotcha, no worries! I guarantee if you don't change the single quotes to doubles in the chdir it won't work right though.
PHP Code:
// Notice the syntax highlighting of the various $forumpaths here
// Red text is a string while blue is a variable
$forumpath 'site/forums/';
echo 
'$forumpath'// Will display '$forumpath' literally
echo "$forumpath"// Will display 'site/forums/'; 

In that post you linked, there is a variable called $limit and its value is set to 5.
PHP Code:
$limit 5
Seems like you accidentally removed that between your $fid= and $forumpath= vars.
Without setting the value of $limit, this query
PHP Code:
// GET THREADS
    
$query $db->simple_select('threads''*'"fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}"); 
is going to throw a syntax error (and stop execution, I'd assume?) because you're trying to use a variable, $limit, without defining it.
My Plugins: [1.8]|[1.6]

** Selling custom plugin that enables Bitcoin payments. PM me if interested in purchasing! **
Reply
#5
Ah ok, I've done what you've recommended the entire code works in terms of integrating the forum threads, however, the pagination portion of the code seems to have no affect on providing extra pages for my post after a certain amount. The code is probably too outdated for the current forum software, code probably needs tampering worth a shot. I'll mess around with it some more!
Reply
#6
(07-16-2017, 05:21 PM)Spudz007 Wrote: Ah ok, I've done what you've recommended the entire code works in terms of integrating the forum threads, however, the pagination portion of the code seems to have no affect on providing extra pages for my post after a certain amount. The code is probably too outdated for the current forum software, code probably needs tampering worth a shot. I'll mess around with it some more!

What exactly are you trying to do?
My Plugins: [1.8]|[1.6]

** Selling custom plugin that enables Bitcoin payments. PM me if interested in purchasing! **
Reply
#7
Well from what I read in that thread I posted the link of, the "Multi-Page" is an extra code you can add towards the original news code that will give you an archive of extra pages that show older news on the website after a certain amount of posts are reached.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)