PDA

View Full Version : Resolved How do I interpret error message?


1andyw
11-12-2008, 10:56 PM
Resolved, thanks.

Hi,

I am dealing with an error in my syntax. My question is where does the error exist in relation to the error message?

This is the message:

Query FailedYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN category ON article.cat_id = category.cat_id WHERE
1064

This is the query:

$sql = "INSERT INTO `article` (heading,content,ord,cat_id) VALUES ('$heading','$article','$ord','$catId')
INNER JOIN category ON article ON article.cat_id = category.cat_id
WHERE
`category`.`cat_id`= $catId AND `page`.`page_id`=$pageId";

Thanks,

Andy

bazz
11-13-2008, 01:28 AM
This is the query:

$sql = "INSERT INTO `article` (heading,content,ord,cat_id) VALUES ('$heading','$article','$ord','$catId')
INNER JOIN category ON article ON article.cat_id = category.cat_id
WHERE
`category`.`cat_id`= $catId AND `page`.`page_id`=$pageId";

Thanks,

Andy

I am not sure I know about joining tables on an insert but, assuming that you need to know how to clarify a join then it should be like this. The highlighted text should be in one of those places but not both. Look into aliases. Basically, the ART and the CAT are tagging the field_names so that there is no ambiguity when, for example, two tables have a field of the same name. ART.field_name clarifies that the filed that matters is the one in the articles table. CAT.field_name is relating to the field_name in the category table.

That as good as I can explain it.


$sql = "INSERT INTO article as ART (heading,content,ord,cat_id) VALUES ('$heading','$article','$ord','$catId') as ART
INNER JOIN category as CAT
ON ART.cat_id = CAT.cat_id
AND CAT.cat_id = $catId
AND CAT.page_id = $pageId;

1andyw
11-13-2008, 09:26 AM
Thank you, Bazz. You are right.

Andy