MyBB Community Forums

Full Version: Sql problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello all.. i've downloaded a plugin from mybbcentral.com
but when i active it, it tells me:
mybb Wrote:MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1060 - Duplicate column name 'userbbcodes'
Query:
ALTER TABLE mybb_users ADD userbbcodes TEXT NOT NULL ;

Please contact the MyBB Group for support.

Here's the code of the plugin
<?php
/**
 *	User BBCodes
 *
 * Allows users to set what their post will automatically get added to the beginning and end
 *
 * Copyright 2008 Nickman
 */

if(!defined("IN_MYBB")) {
    die("This file cannot be accessed directly.");
}

$plugins->add_hook("usercp_start", "userbbcode");
$plugins->add_hook("newreply_do_newreply_start","userbbcode_post");
$plugins->add_hook("newthread_do_newthread_start","userbbcode_post");

function userbbcode_info() {
    return array(
        "name"				=> "User BBCodes",
        "description"		=> "Allows users to set the default look of their post",
        "website"			=> "http://mybbsource.com",
        "author"			=> "Nickman",
        "authorsite"		=> "http://mybbsource.com",
        "version"			=> "1.0"
    );
}

function userbbcode_activate() {
	global $db;

	$db->query("ALTER TABLE ".TABLE_PREFIX."users ADD `userbbcodes` TEXT NOT NULL ;");

	require MYBB_ROOT."/inc/adminfunctions_templates.php";
	$template = array(
		"title"		=> "usercp_userbbcode",
		"template"	=> '<html>
<head>
<title>{$mybb->settings[bbname]} - Default Post Format</title>
{$headerinclude}
</head>
<body>
{$header}
<form action="usercp.php" method="post">
<table width="100%" border="0" align="center">
<tr>
{$usercpnav}
<td valign="top">
<table border="0" cellspacing="{$theme[borderwidth]}" cellpadding="{$theme[tablespace]}" class="tborder">
<tr>
<td class="thead" colspan="2"><strong>Default Format</strong></td>
</tr>
<tr>
<td align="center" class="trow1" width=\"100%\">
<p>Enter What You Want All Your Posts To Be Auto-Formatted Like<br/>
Use {MESSAGE} as your post<br/>
For Example To Have All Your Posts Bold Put
<blockquote> [b]{MESSAGE}[/b]</blockquote>
<input type="text" name="userbbcodes" value="{$mybb->user[userbbcodes]}"/>
</td>
</tr>
</table>
<br />
<div align="center">
<input type="hidden" name="action" value="do_userbbcodes" />
<input type="submit" class="button" name="submit" value="Update Format" />
</div>
</td>
</tr>
</table>
</form>
{$footer}
</body>
</html>
',
		"sid"		=> -1
	);
	$db->insert_query("templates", $template);

find_replace_templatesets("usercp_nav_misc", '#</tbody>#', '<tr><td class="trow1 smalltext"><a href="usercp.php?action=userbbcode" class="usercp_nav_item usercp_nav_usergroups">User BBCodes</a></td></tr></tbody>');
}

function userbbcode_deactivate() {
	global $db;
	require MYBB_ROOT."/inc/adminfunctions_templates.php";
$db->query("ALTER TABLE ".TABLE_PREFIX."users DROP userbbcodes");
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='usercp_userbbcode'");

}

function userbbcode() {
	global $header,$headerinclude,$usercpnav,$footer,$mybb,$theme,$db,$lang,$templates;
	if ($mybb->input['action'] == "userbbcode")
	{
	eval("\$editprofile = \"".$templates->get("usercp_userbbcode")."\";");
	output_page($editprofile);
	}
	elseif ($mybb->input['action'] == "do_userbbcodes")
	{
		$stuff=htmlspecialchars($mybb->input['userbbcodes']);
		$uid=$mybb->user[uid];
		if ($db->query("UPDATE ".TABLE_PREFIX."users SET userbbcodes='$stuff' WHERE uid='$uid'"))
		{
		redirect("usercp.php","Default Format Updated!");
	}
	}
	else {
		return;
	}
}
function userbbcode_post()
{
	global $mybb,$db;
	$message=$mybb->input['message'];

	if ($mybb->user['userbbcodes'] != "")
	{

		$user=preg_split("#{MESSAGE}#ims",$mybb->user['userbbcodes']);
		if ($user[0] AND $user[1])
		{
		$message=$user[0].$message.$user[1];
		}
		$mybb->input['message']=$message;
		return;
	}
}


What should i do?

PS: have i posted in the wrong section? if yes.. please move this thread Blush
Moved..

Did you install this plugin before? I'll try and find the line it's on and tell you how to fix it.
[Edit:]
Remove this line:
$db->query("ALTER TABLE ".TABLE_PREFIX."users ADD `userbbcodes` TEXT NOT NULL ;");

right after "global $db;"