Copy link to clipboard
Copied
I'm getting an error on PHP code that is supposed to generate a MYSQL query from an advanced search form. The following error is appearing:
Parse error: syntax error, unexpected T_VARIABLE in /Users/arisspenjian/Sites/cementmonkey/results.php on line 62
I can't figure out what's wrong with the code.
58 mysql_select_db($database_cementmonkey, $cementmonkey); 59 $query_rsMainItems = 'SELECT * FROM mainitems'; 60 $where = false; 61 if (isset($_GET['category']) && !empty($_GET['category'])) { 62 $query_rsMainItems .= 'WHERE category = '. GetSQLValueString($_GET['category'], 'text'); 63 $where = true;
Any ideas?
Copy link to clipboard
Copied
While I am no expert, I would start by simplyfing the query.
I would remove the conditional statement to test only the query on top with a fixed value.
Since the error is after that query make sure that a query really works then move on to test the logic section below and then the second query.
Several other thoughts occur.
1. Remove the first peroid . on line 62 before the = sign.
2. Change the name of your boolien variable, $where is possibly a reserved word, and probably confusing to anyone but you.
3. Did you use Dreamweaver to generate the querries? It looks like your missing lines of code.
58 mysql_select_db($database_cementmonkey, $cementmonkey);
59 $query_rsMainItems = 'SELECT * FROM mainitems';
60 $where = false;
61 if (isset($_GET['category']) && !empty($_GET['category'])) {
62 $query_rsMainItems .= 'WHERE category = '. GetSQLValueString($_GET['category'], 'text');
63 $where = true;
-Daniel Hoviss
Copy link to clipboard
Copied
OK, from this code
$query_rsMainItems .= 'WHERE category = '. GetSQLValueString($_GET['category'], 'text');
change to this
$query_rsMainItems .= ' WHERE category = %s',(GetSQLValueString($_GET['category']), 'text');
You must put space before WHERE otherwise the query will look like
SELECT * FROM mainitemsWHERE category
instead of SELECT * FROM mainitems WHERE category
And that's why u get the mysql syntax error
Copy link to clipboard
Copied
I just tried that and it didn't solve my problem. I also added the %s you
included, and I'm not sure if you meant to put a comma after the %s or it
was just a typo, which was meant to be a period. But either way, I tried
both and nothing ... any other thoughts? If it says that the error is in
line 62, does that mean that it is DEFINITELY in line 62 or could there be
some other problem?
Copy link to clipboard
Copied
Ya, if it said line 62 means there's some mistakes in that line, or maybe at line 61@63 too. Have u put the space before WHERE? If u done that, i think u have miss the } symbol after $where = true. Try this one
if (isset($_GET['category']) && !empty($_GET['category'])) {
$query_rsMainItems .= ' WHERE category = '. $_GET['category'];
$where = true;
}
My previous code is okay too but i made some mistakes in it. It should be
$query_rsMainItems .= ' WHERE category = %s', GetSQLValueString($_GET['category'], 'text');