Hi Guys,
I have a text field in my app that the user can enter any text they want into including quotes and apostrophes.
Does anyone know if there is a way I can sanitize the input before inserting it into my database?
I thought maybe some sort of prepared statement but I haven’t been able to get it working.
I have tried many variations of the below statement including with and without quotes in the braces before and after …note…
coinID is an Int and note is String.
db:prepare[[INSERT INTO user_notes VALUES (]]…coinID…[[,]]…note…[[);]]
db:exec()
I tried this as well but I don’t quite know the syntax or even if it is supported:
db.prepare([[INSERT INTO user_notes VALUES (?), (?);]], coinID, notes)
I tried this too:
local s = db:prepare(“INSERT INTO user_notes (coinID, note) VALUES (:f, :s);”)
s:bind(":f", row.id)
s:bind(":s", row.notes)
db:exec(s)
but it states bad argument #1 to ‘bind’ (number expected, got string).
I’m trying to execute this statement within a for row in nrows statement if that makes a difference.
I also tried doing gSubs on the notes string to add back spaces before " and ’ but again, couldn’t seem to get it working.
I want the user to add as many quotes or apostrophes as they want without it having an effect on the SQL.
If someone has any advice I’d love to heard it :).
Kind Regards,
Krivvenz.
