28

I have encountered some websites that when I used -- to comment the rest of the query it didn't work, but when I tried --+ it worked.

In the MySQL official documentation there is no such thing as --+ and we only have -- and two other ways.

Why does this happen (in detail)? I want to know exactly why this works sometimes and -- doesn't, and why there is no --+ for comments in the MySQL man page?

3
  • 2
    I suppose your question is more related to HTTP than to SQL... Commented Oct 22, 2018 at 15:44
  • 8
    @YourCommonSense i had no idea its related to HTTP and not SQL, so why this happens? Commented Oct 22, 2018 at 16:01
  • You can also use # which doesn't need a space after
    – paj28
    Commented Oct 22, 2018 at 16:47

2 Answers 2

59

From the documentation:

From a -- sequence to the end of the line. In MySQL, the -- (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on). This syntax differs slightly from standard SQL comment syntax, as discussed in Section 1.8.2.4, “'--' as the Start of a Comment”.

(emphasis mine)

Many URL decoders treat + as a space.

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Rory Alsop
    Commented Oct 24, 2018 at 18:44
0

MySQL requires a blank space followed by the double dashes like "-- " and a URL can't contain blank spaces but the + sign can be used as blank space. That's why these comments are followed up by "+".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .