MyBB Community Forums

Full Version: MyBB integration database error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey there.
I'm trying to build my site around MyBB and it's login system, and what I'm working on is an area for users to submit content and have it stored in a database not of MyBB's (specifically now, a user blogging system).

I followed elements of the MyBB integration tutorial to do this.
This is included at the top of the document:
<?php
    define("IN_MYBB",1);
    chdir('../forum'); // path to MyBB
    require './global.php';
?>
I need that because the page needs to call for the logged-in user's username an uid.


Along the lines of the page, this affected form is included:
<?php
if($mybb->user['uid'])
{
// Display blog posting form
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p><strong>Title :</strong><br />
  <input type="input" name="title" size="25" maxlength="70" width="500" value="<?php if(isset($_POST['title'])) echo $_POST['title']; ?>" />
</p>
<!-- Author name and UID START -->
<input type="hidden" name="author_username" maxlength="11" value="<?php echo "".$mybb->user['username'].""; ?>" />
<input type="hidden" name="author_uid" maxlength="50" value="<?php echo "".$mybb->user['uid'].""; ?>" />
<!-- Author name and UID END -->
<p><strong>Your post:</strong><br />
<textarea cols="100" rows="10" name="blog_post"><?php if(isset($_POST['blog_post'])) echo $_POST['blog_post']; ?></textarea></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" /></p>
</form>
<?php
}
else
{
// The user is not logged in
echo "You are not logged in. Please log in or register to post a blog post.";
}
?>
If you're wondering why the form action is $_SERVER['PHP_SELF'];, it's because I need the form to return to the same page with errors of the input fields.

Anywho, my database connection is to x_blogs.
I get this error when I submit the form:
Quote:MySQL error: 1146
Table 'x_blogs.mybb_users' doesn't exist
Query: UPDATE mybb_users SET lastactive='1208999094', timeonline=timeonline+7 WHERE uid='1' LIMIT 1
Why is it calling for mybb_users? Is it something in the global.php file? How can I change that for the form submission? It's trying to write to the wrong database.

If anyone can help me out with this, I'd really appreciate it.
gamebittk Wrote:Anywho, my database connection is to x_blogs.
I get this error when I submit the form:
Quote:MySQL error: 1146
Table 'x_blogs.mybb_users' doesn't exist
Query: UPDATE mybb_users SET lastactive='1208999094', timeonline=timeonline+7 WHERE uid='1' LIMIT 1
Why is it calling for mybb_users? Is it something in the global.php file? How can I change that for the form submission? It's trying to write to the wrong database.

If anyone can help me out with this, I'd really appreciate it.

Yes, for the sessions and user info to be retrieved, the global script needs to access the MyBB database.
Thanks. But how can I make not try to access that database for this form?
The user login check and the form submission are two different things.
If you are calling global.php, I suggest that you leave MyBB to connect to the normal MyBB database. After global.php finishes executing, you can use www.php.net/mysql_select_db to change the database to your site's database.

global.php needs access to the MyBB database in order to determine the current user information, which you are using on the page ($mybb->user...)
I understand what you're saying. I know that I need global.php.
I also selected the db specifically but got the same error.

The problem is that even when I select the database specifically, I still get "Table 'x_blogs.mybb_users' doesn't exist".

I know that global.php calls mybb_users, but why can't I call x_blogs specifically when using mysql_connect?
Where are you selecting the database specifically? Which part of the code is this?
The database is loaded on submit, in mysql_connect.php.
The form calls $_SERVER['PHP_SELF'];, the current document, and on submit:
if (isset($_POST['submitted'])) {
include ('mysql_connect.php');
if (empty($_POST['title'])) {...(some error checking)...
...
else {
$blog_post = $_POST['blog_post'];
} ...
if ($title && $author_username && $author_uid && $blog_post) {
$query = "INSERT INTO posts (title, author_username, author_uid, post, date) VALUES ('$title', '$author_username', '$author_uid', '$post', NOW())";
$result = @mysql_query($query);
if ($result) {
echo '<p><font color="red">Congratulations! Your post was successfully submitted. You will now be redirected to it.</font></p>';
} else {
...
And the mysql_connect is almost the same as on the link you gave me:
<?php

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}
?>
Can you upload the entire files. Sorry, it's hard to follow what you have going on.
Well, thanks to your help, the form successfully submits, but for some reason I still get that error (even with success) so I gotta work on removing that.

I can PM you the files.

Thanks a lot for your help, Dennis.
Pages: 1 2