Syntax is the scientific study of or the academic examination of how units of language, such as morphemes and lexemes, join together to create larger units--called phrases, clauses, and sentences--that are acceptable in a given language or in a universal model of language.
Grammar is a record, either a prescriptive record or a descriptive record, of how components of syntactical study present in a given or a universal language to produce through logical and structural forms an acceptable effective spoken or written communication.
Working backwards, grammar prescribes that the English sentence "The cats meow" comprises a determiner phrase (the cats) and a verb. Grammar also prescribes that the determiner phrase must precede the verb (meow).
If a particular dialect of English has the acceptable structure "Meow the cats," grammar may describe that the sentence comprises a verb (meow) followed by a determiner phrase (the cats). Descriptive grammar would explain how in Xzv dialect a verb may precede a determiner phrase.
The difference between prescriptive grammar and descriptive grammar is that a prescriptive grammar prescribes forms and rules to be followed to establish a standard of a language that takes precedence over other dialects of the language, whereas a descriptive grammar analyses and then describes the grammar that is acceptable and practiced in a given dialect of a language. You might say one is a rule book (prescriptive) whereas the other one is a tour guide (descriptive).
A discussion of syntax, either the scientific study or the academic (student) examination, approaches the same sentence, "The cats meow," from the component parts. Beginning with morphology, the syntax would be analyzed as having the morpheme /s/ attached to the lexeme /cat/ to form a plural /cats/. The syntax would further be analyzed as the lexemes the and cats joined in a phrase with the determiner the as the head word, therefore comprising a determiner phrase (the cats). The syntax would further be analyzed as the determiner phrase joined with an action verb to form the clause the cats meow. The syntax would further be analyzed as the determiner phrase filling the Subject slot and the action verb filling the Verb slot, with a vacant Object slot, rendering it a sentence in the SV sentence structure.
Syntax starts at the deepest level and analyzes component parts of a language sample. Grammar addresses the formation of communicative groups of words, phrases, clauses, and sentences that express intention.
By this definition, grammar may be built upward from syntax, but syntax cannot be built upward from grammar.
Yes, there is a difference. Think of syntax as sentence structure (word order, sentence length, number of clauses, etc.). Grammar is a much broader category which deals with punctuation, parts of speech, word usage, sentence structure, capitalization, and so on.
If your teacher asks you to analyze an author's syntax, you need to discuss specifically that author's sentence length, or the word order within the sentence, or parallelism, or other sentence-oriented issues. If your teacher asks you to discuss grammatical errors, you can certainly point out syntactical issues, but just be aware that syntax is just one part of grammar.