Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL "INSERT" and SQL injection

I have this simple mysql query:

INSERT INTO table (col1, col2) VALUES ('1', '2')

col1 and col2 are foreign keys for another table so any value for col1 and col2 must be present in the other table or otherwise the row won't be inserted.

Is there still any risk of SQL injection in this case? If i receive these col values from PHP POST, do I still need to bind them before insertion into the database or they are already secure as the cols are foreign keys?

like image 809
Michael Samuel Avatar asked Dec 20 '22 10:12

Michael Samuel


1 Answers

Yes. All input from users needs to be check for sanitized. E.g. if a user is sending you a string like that '2'); drop table <table> as your second value it might get executed and giving you some surprise. (String might not work exactly, but I think you got the point)

like image 64
frlan Avatar answered Dec 28 '22 11:12

frlan