r/PHPhelp • u/[deleted] • Oct 13 '19
INSERT INTO sql table not working.
Am I inserting rows into my table correctly? This doesn't work for some reason.
$conn->exec("INSERT INTO Questions_Table (ID, Question, Votes) VALUES ($num_rows, $submitted_question, 1)");6
u/akas84 Oct 13 '19
You are missing quotes in the string and you should check how to bind params or you will have and sql injection on there.
1
2
u/Zinin2018 Oct 13 '19
Whats the difference betn using query or exec?
2
u/greg8872 Oct 13 '19
assuming this is for plain PDO,
query()returns a PDO Statement Object (which you can loop through and process the records returned), whereexec()just runs the query and returns how many rows were affected. So if you doing a query that does not return records and you are not using any data that needs protected (submitted by user), useexec()
0
2
u/PopeInnocentXIV Oct 13 '19
Are
$num_rowsand$submitted_questionproperly quoted and escaped?