hmm it is not about encoding, I tried with latin data and using rows, err := db.Query("SELECT id, name FROM data WHERE name = ?", fullNameQuery)
it is not working why?
Have you already inspected the value of err returned by db.Query()? The error message usually points to the possible reasons for the error.
My guess is that the LIKE errors out:
LIKE '%' ? '%'
Try moving the wildcards outside the query string:
fullNameQuery := "%" + r.FormValue("full_name") + "%"
rows, err := db.Query("SELECT id, full_name, school FROM students WHERE full_name LIKE ? LIMIT 50", fullNameQuery)
there is no error, the program working just return empty slice.
I managed to make it work by omitting the quotation mark of the get parameter fullNameQuery.
is that normal?
Ok, so the quotation marks are part of the queryFullName string. Yes, these quotation marks can get in the way, The SQL query would then search for %"John"% instead of %John%.
If you don’t want to (or cannot) remove the quotes from the URL, you can use strings.Trim(fullNameQuery, "\"") to remove the quotation marks from fullNameQuery,
If fullNameQuery then still includes quotation marks, inspect those quotation marks closer. Maybe they are not the usual straight quotes " but rather “curved” quotes (see this list, code points U+201C and U+201D). You can add these to the “cutset” (like so: string.Trim(stringToTrim, "\"“”") and Trim will then remove them as well.
Edit: here is the cutset again but enlarged, so that the difference between straight and curved quotes becomes more visible: