I think we have abit of a language barrier at the moment.
The code is fine. It works 100%. I've tested it myself on my server. I've tried different values of $mycateg, ranging from integers, to single words and complete sentences. It still works flawlessly. The problem is not the code.
Somewhere in your script one ore more variables (the ones with a $-sign infront) is assigned a value that makes something brake. In order to know what variable has a faulty value is to echo / print / dump them, and verify the contents manually.
That is why I asked you to echo your query, and not run it through your database. We need to read it with our own eyes, manually, in order to make sure it checks out.
Code: Select all
SELECT * FROM products WHERE category = '$mycateg' LIMIT $offset, $rowsPerPage
Assuming $mycateg is a valid string, which you yet have confirmed, you still have two more variables which can contain all sorts of values. There's also inconsistencys in your code. You first direct your links to index.php (row 29), and later on in the script, you direct the links to PHP_SELF. Is the two the same file, or two different files?
What does $_REQUEST['category'] contain? print_r() or var_dump() it. Do the same with $mycateg, and please share the output with us. The output should not be a SQL-error, since echo, var_dump() and/or print_r() does not interact with the database.
My guess is that there's a problem with $_REQUEST['category'], which in turn causes $mycateg to inherit the error, which in turn causes a SQL-syntax error.