MyBB Community Forums

Full Version: SQL Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been trying to do a template system for a site and so far all pages except for 1 are working. The query it is attempting to run is
 SELECT * FROM `templates` WHERE `name` IN ('forumdisplay', 'threadlist', 'modoptions', 'forumjump', 'moderatorlist', 'doctype', 'header', 'header_log_in', 'navbar', 'logo', 'redirect', 'footer')

This works fine in PHPMyAdmin, but when it runs it on a site it gets an error somehow.

This is generated from the following code:
$templatelist .= ",doctype,header,header_log_in,navbar,logo,redirect,footer";
$explodedtemplates = explode(",", $templatelist);
$finish = count($explodedtemplates);
$start = 0;
$comma = ", ";
foreach($explodedtemplates as $template)
{
	$where .= "'" . $template . "'";
	++$start;
	if ($start==$finish)
	{
		$comma = "";
	}
	$where .= $comma;
}
$where = preg_replace("/\A(.*?)([,])\Z/is", "$1", $where);
$query = "SELECT * FROM `templates` WHERE `name` IN ({$where})";
$query = $db->query($query);

The fact that the variable $templatelist starts with a comma is irrelevant because this is a global file and the file that is including it has the variable ending in a template name instead of a comma.

Any help?
Any idea as to what the error is? Might make it easier to debug
It claimed it to be invalid syntax near where it started to list the templates. Somehow by just recoding from scratch the error disappeared. I'm thinking maybe its because I used a variable name in the regular file besides $templatelist that impacts how a certain query is formed. That probably confused it.
There's a beginning comma on this line;
$templatelist .= ",doctype,header,header_log_in,navbar,logo,redirect,footer";
Change this to;
$templatelist .= "doctype,header,header_log_in,navbar,logo,redirect,footer";
why do you do "$1"? do you mean "\$1" ? "$1" means $1 you don't have any $1 variable.
(2012-06-17, 04:12 PM)jung3o Wrote: [ -> ]why do you do "$1"? do you mean "\$1" ? "$1" means $1 you don't have any $1 variable.
It's in there for substitution.
(2012-06-17, 04:14 PM)Josh H. Wrote: [ -> ]
(2012-06-17, 04:12 PM)jung3o Wrote: [ -> ]why do you do "$1"? do you mean "\$1" ? "$1" means $1 you don't have any $1 variable.
It's in there for substitution.

well then it should be '$1' instead of "$1" because quotes DO matter.
(2012-06-18, 12:00 AM)jung3o Wrote: [ -> ]
(2012-06-17, 04:14 PM)Josh H. Wrote: [ -> ]
(2012-06-17, 04:12 PM)jung3o Wrote: [ -> ]why do you do "$1"? do you mean "\$1" ? "$1" means $1 you don't have any $1 variable.
It's in there for substitution.

well then it should be '$1' instead of "$1" because quotes DO matter.
Not in this case, because of them being entirely different parameters.
(2012-06-18, 02:32 AM)Josh H. Wrote: [ -> ]Not in this case, because of them being entirely different parameters.

ah, I was thinking of the wrong thing... sorry, what I'm saying is only for variables (variables with numbers are invalid)
http://codepad.org/aVA8x876
I know what you were thinking... I think :p