So I'm pretty new to SQL so I'm not too familiar with how to prevent any SQL injections.
I have 1 main form that's being used as a poll and it currently only has 1 text field. At the moment I think I'm safe from the generic '); DROP TABLE table; -- exploit but there are more I'm not too sure about.
Below are my insert and update lines. $want is the text field I mentioned.
INSERT INTO polls (ip, continent, hours, timespent, f_champ, l_champ, o_champ, u_champ, b_champ, w_champ, want, story, happy, 4star, 3star, 2star, 1star) VALUES ($ip, '$continent', $hours, '$timespent', '$f_champ', '$l_champ', '$o_champ', '$u_champ', '$b_champ', '$w_champ', CAP_FIRST('$want'), '$story', '$happy', $_4star, $_3star, $_2star, $_1star)
UPDATE polls SET continent = '$continent', hours = $hours, timespent = '$timespent', f_champ = '$f_champ', l_champ = '$l_champ', o_champ = '$o_champ', u_champ = '$u_champ', b_champ = '$b_champ', w_champ = '$w_champ', want = CAP_FIRST('$want'), story = '$story', happy = '$happy', 4star = $_4star, 3star = $_3star, 2star = $_2star, 1star = $_1star WHERE ip = $ip
I'm currently using PHP and MySQLi (procedural) inserting into a phpMyAdmin database.
Can anyone provide any tips to stop potential injections. Thanks.
UPDATEstatement if someone manages to getAfrica'--into$continent? Use prepared statements, and bind variables. If, for some reason, you absolutely can't use bindings, sanitize your input first. Allowing nothing but alphanumerics helps in most cases. – Guntram Blohm Feb 11 '15 at 21:00