I'm trying to better understand parameterized sql as a solution to SQL injection.
Lets say I have a tblCustomer
with the fields CustName
, Phone
and Address
. Lets also say I have an input form for new customers to enter their data, with controls called txtName
, txtPhone
and txtAddress
.
I could run the following vba code:
dim strName, strPhone strAddress, strSQL as string
strName = me.txtName
strPhone = me.txtPhone
strAddress = me.txtAddress
strSQL = "INSERT INTO tblCustomer (CustName, Phone, Address) _
VALUES (" & strName & ", " & strPhone & ", " & strAddress & ");"
DoCmd.RunSQL strSQL
But then if someone nominated the address "Robert'); DROP TABLE tblCustomer; --" (wink) I'd have some serious problems.
I've used vba parameters, but they aren't helping me. So when people say use parameters to fix the issue, what do they mean?